2017-01-01 07:50:51 +01:00
# Copyright 1997-2017 Free Software Foundation, Inc.
2009-09-15 05:32:06 +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/>.
# This program tests the 'catch syscall' functionality.
#
# It was written by Sergio Durigan Junior <sergiodj@linux.vnet.ibm.com>
# on September/2008.
test suite update - gdb.base/[cd]
Convert files gdb.base/[cd]*.exp to use standard_output_file et al.
* call-ar-st.exp, call-rt-st.exp, call-sc.exp,
call-signal-resume.exp, call-strs.exp, callexit.exp,
callfuncs.exp, catch-load.exp, catch-syscall.exp, charset.exp,
checkpoint.exp, chng-syms.exp, code-expr.exp, code_elim.exp,
commands.exp, completion.exp, complex.exp, cond-expr.exp,
condbreak.exp, consecutive.exp, constvars.exp, corefile.exp,
ctxobj.exp, cursal.exp, cvexpr.exp, dbx.exp, default.exp,
define.exp, del.exp, detach.exp, dfp-test.exp, display.exp,
dmsym.exp, dump.exp, dup-sect.exp: Use standard_testfile,
standard_output_file, prepare_for_testing, clean_restart.
2013-06-27 20:49:03 +02:00
standard_testfile
2009-09-15 05:32:06 +02:00
2016-12-23 17:52:18 +01:00
if { [prepare_for_testing "failed to prepare" $testfile ${testfile}.c] } {
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
return -1
}
2016-06-28 13:02:35 +02:00
# Check target supports catch syscall or not.
clean_restart $binfile
if ![runto_main] then {
2016-12-01 21:40:05 +01:00
fail "can't run to main"
2016-06-28 13:02:35 +02:00
return
}
set test "catch syscall"
gdb_test_multiple $test $test {
-re "The feature \'catch syscall\' is not supported.*\r\n$gdb_prompt $" {
unsupported "catch syscall isn't supported"
return -1
}
-re ".*$gdb_prompt $" {
pass $test
}
}
set test "check catch syscall"
gdb_test_multiple "continue" $test {
-re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" {
unsupported "catch syscall isn't supported"
return -1
}
-re ".*Catchpoint.*$gdb_prompt $" {
pass $test
}
}
Support catch syscall on aarch64 linux
Hi,
This patch is to support catch syscall on aarch64 linux. We
implement gdbarch method get_syscall_number for aarch64-linux,
and add aarch64-linux.xml file, which looks straightforward, however
the changes to test case doesn't.
First of all, we enable catch-syscall.exp on aarch64-linux target,
but skip the multi_arch testing on current stage. I plan to touch
multi arch debugging on aarch64-linux later.
Then, when I run catch-syscall.exp on aarch64-linux, gcc errors that
SYS_pipe isn't defined. We find that aarch64 kernel only has pipe2
syscall and libc already convert pipe to pipe2. As a result, I change
catch-syscall.c to use SYS_pipe if it is defined, otherwise use
SYS_pipe2 instead. The vector all_syscalls in catch-syscall.exp can't
be pre-determined, so I add a new proc setup_all_syscalls to fill it,
according to the availability of SYS_pipe.
Regression tested on {x86_64, aarch64}-linux x {native, gdbserver}.
gdb:
2015-03-18 Yao Qi <yao.qi@linaro.org>
PR tdep/18107
* aarch64-linux-tdep.c: Include xml-syscall.h
(aarch64_linux_get_syscall_number): New function.
(aarch64_linux_init_abi): Call
set_gdbarch_get_syscall_number.
* syscalls/aarch64-linux.xml: New file.
gdb/testsuite:
2015-03-18 Yao Qi <yao.qi@linaro.org>
PR tdep/18107
* gdb.base/catch-syscall.c [!SYS_pipe] (pipe2_syscall): New
variable.
* gdb.base/catch-syscall.exp: Don't skip it on
aarch64*-*-linux* target. Remove elements in all_syscalls.
(test_catch_syscall_multi_arch): Skip it on aarch64*-linux*
target.
(setup_all_syscalls): New proc.
2015-03-18 11:47:45 +01:00
# All (but the last) syscalls from the example code. It is filled in
# proc setup_all_syscalls.
set all_syscalls { }
2009-09-15 05:32:06 +02:00
set all_syscalls_numbers { }
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
2009-09-15 05:32:06 +02:00
# The last syscall (exit()) does not return, so
# we cannot expect the catchpoint to be triggered
# twice. It is a special case.
set last_syscall "exit_group"
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
set last_syscall_number { }
2009-09-15 05:32:06 +02:00
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
set vfork_syscalls "(vfork|clone2?)"
set unknown_syscall_number { }
2009-09-15 05:32:06 +02:00
# Internal procedure used to check if, after issuing a 'catch syscall'
# command (without arguments), the 'info breakpoints' command displays
# that '"any syscall"' is to be caught.
proc check_info_bp_any_syscall {} {
# Verifying that the catchpoint appears in the 'info breakpoints'
# command, but with "<any syscall>".
set thistest "catch syscall appears in 'info breakpoints'"
gdb_test "info breakpoints" ".*catchpoint.*keep y.*syscall \"<any syscall>\".*" $thistest
}
# Internal procedure used to check if, after issuing a 'catch syscall X'
# command (with arguments), the 'info breakpoints' command displays
# that the syscall 'X' is to be caught.
proc check_info_bp_specific_syscall { syscall } {
set thistest "syscall(s) $syscall appears in 'info breakpoints'"
gdb_test "info breakpoints" ".*catchpoint.*keep y.*syscall(\[(\]s\[)\])? (.)?${syscall}(.)?.*" $thistest
}
# Internal procedure used to check if, after issuing a 'catch syscall X'
# command (with many arguments), the 'info breakpoints' command displays
# that the syscalls 'X' are to be caught.
proc check_info_bp_many_syscalls { syscalls } {
set filter_str ""
foreach name $syscalls {
set filter_str "${filter_str}${name}, "
}
set filter_str [ string trimright $filter_str ", " ]
set thistest "syscalls $filter_str appears in 'info breakpoints'"
gdb_test "info breakpoints" ".*catchpoint.*keep y.*syscalls (.)?${filter_str}(.)?.*" $thistest
}
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
# This procedure checks if there was a call to a syscall. The optional
# pattern can match syscalls that vary in implementation, like vfork.
proc check_call_to_syscall { syscall { pattern "" } } {
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
global decimal
2009-09-15 05:32:06 +02:00
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
if { $pattern eq "" } {
set pattern "${syscall}"
}
2009-09-15 05:32:06 +02:00
set thistest "program has called $syscall"
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
gdb_test "continue" "Catchpoint $decimal \\(call to syscall .?${pattern}.?\\).*" $thistest
2009-09-15 05:32:06 +02:00
}
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
# This procedure checks if the syscall returned. The optional pattern
# can match syscalls that vary in implementation, like vfork.
proc check_return_from_syscall { syscall { pattern "" } } {
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
global decimal
2009-09-15 05:32:06 +02:00
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
if { $pattern eq "" } {
set pattern "${syscall}"
}
2009-09-15 05:32:06 +02:00
set thistest "syscall $syscall has returned"
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
gdb_test "continue" "Catchpoint $decimal \\(returned from syscall ${pattern}\\).*" $thistest
2009-09-15 05:32:06 +02:00
}
# Internal procedure that performs two 'continue' commands and checks if
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
# a syscall call AND return occur. The optional pattern can match
# syscalls that vary in implementation, like vfork.
proc check_continue { syscall { pattern "" } } {
2009-09-15 05:32:06 +02:00
# Testing if the 'continue' stops at the
# specified syscall_name. If it does, then it should
# first print that the infeior has called the syscall,
# and after print that the syscall has returned.
2015-03-11 12:50:12 +01:00
# Testing if the inferior has called the syscall.
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
check_call_to_syscall $syscall $pattern
2009-09-15 05:32:06 +02:00
# And now, that the syscall has returned.
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
check_return_from_syscall $syscall $pattern
2009-09-15 05:32:06 +02:00
}
# Inserts a syscall catchpoint with an argument.
proc insert_catch_syscall_with_arg { syscall } {
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
global decimal
2009-09-15 05:32:06 +02:00
# Trying to set the catchpoint
set thistest "catch syscall with arguments ($syscall)"
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
gdb_test "catch syscall $syscall" "Catchpoint $decimal \\(syscall \'?${syscall}\'?( \[${decimal}\])?\\)" $thistest
2009-09-15 05:32:06 +02:00
check_info_bp_specific_syscall $syscall
}
# Inserts a syscall catchpoint with many arguments.
proc insert_catch_syscall_with_many_args { syscalls numbers } {
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
global decimal
2009-09-15 05:32:06 +02:00
set catch [ join $syscalls " " ]
set filter_str ""
foreach name $syscalls number $numbers {
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
set filter_str "${filter_str}'${name}' \\\[${number}\\\] "
2009-09-15 05:32:06 +02:00
}
set filter_str [ string trimright $filter_str " " ]
# Trying to set the catchpoint
set thistest "catch syscall with arguments ($filter_str)"
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
gdb_test "catch syscall $catch" "Catchpoint $decimal \\(syscalls ${filter_str}\\).*" $thistest
2009-09-15 05:32:06 +02:00
check_info_bp_many_syscalls $syscalls
}
proc check_for_program_end {} {
# Deleting the catchpoints
delete_breakpoints
2011-03-07 17:03:04 +01:00
gdb_continue_to_end
2009-09-15 05:32:06 +02:00
}
proc test_catch_syscall_without_args {} {
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
global all_syscalls last_syscall vfork_syscalls unknown_syscall_number decimal
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
with_test_prefix "without arguments" {
# Trying to set the syscall.
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
gdb_test "catch syscall" "Catchpoint $decimal \\(any syscall\\)"
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
check_info_bp_any_syscall
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
# We have to check every syscall.
foreach name $all_syscalls {
check_continue $name
}
2009-09-15 05:32:06 +02:00
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
check_continue "vfork" $vfork_syscalls
with_test_prefix "ENOSYS" {
check_continue $unknown_syscall_number
}
2013-10-09 16:31:35 +02:00
# At last but not least, we check if the inferior has called
# the last (exit) syscall.
check_call_to_syscall $last_syscall
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
# Now let's see if the inferior correctly finishes.
check_for_program_end
}
2009-09-15 05:32:06 +02:00
}
proc test_catch_syscall_with_args {} {
2013-10-09 16:31:35 +02:00
with_test_prefix "with arguments" {
set syscall_name "close"
insert_catch_syscall_with_arg $syscall_name
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
# Can we continue until we catch the syscall?
check_continue $syscall_name
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
# Now let's see if the inferior correctly finishes.
check_for_program_end
}
2009-09-15 05:32:06 +02:00
}
proc test_catch_syscall_with_many_args {} {
2013-10-09 16:31:35 +02:00
with_test_prefix "with many arguments" {
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
global all_syscalls all_syscalls_numbers
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
insert_catch_syscall_with_many_args $all_syscalls $all_syscalls_numbers
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
# Can we continue until we catch the syscalls?
foreach name $all_syscalls {
check_continue $name
}
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
# Now let's see if the inferior correctly finishes.
check_for_program_end
}
2009-09-15 05:32:06 +02:00
}
proc test_catch_syscall_with_wrong_args {} {
2013-10-09 16:31:35 +02:00
with_test_prefix "wrong args" {
# mlock is not called from the source
set syscall_name "mlock"
insert_catch_syscall_with_arg $syscall_name
# Now, we must verify if the program stops with a continue.
# If it doesn't, everything is right (since we don't have
# a syscall named "mlock" in it). Otherwise, this is a failure.
set thistest "catch syscall with unused syscall ($syscall_name)"
gdb_continue_to_end $thistest
}
2009-09-15 05:32:06 +02:00
}
proc test_catch_syscall_restarting_inferior {} {
2013-10-09 16:31:35 +02:00
with_test_prefix "restarting inferior" {
set syscall_name "chroot"
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
with_test_prefix "entry" {
insert_catch_syscall_with_arg $syscall_name
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
# Let's first reach the entry of the syscall.
check_call_to_syscall $syscall_name
}
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
with_test_prefix "entry/return" {
# Now, restart the program.
rerun_to_main
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
# And check for entry/return.
check_continue $syscall_name
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
# Can we finish?
check_for_program_end
}
}
2009-09-15 05:32:06 +02:00
}
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
proc test_catch_syscall_skipping_return {} {
with_test_prefix "skipping return" {
with_test_prefix "entry" {
set syscall_name "write"
insert_catch_syscall_with_arg $syscall_name
# Let's first reach the entry of the syscall.
check_call_to_syscall $syscall_name
# Now purposely skip the syscall return.
delete_breakpoints
gdb_test "stepi" ".*" "step over syscall return"
}
# With a naive entry/return toggle, gdb will still think
# the target is due for a syscall return.
with_test_prefix "entry/return" {
set syscall_name "read"
insert_catch_syscall_with_arg $syscall_name
# Check for entry first, then return.
check_continue $syscall_name
# Can we finish?
check_for_program_end
}
}
}
proc test_catch_syscall_mid_vfork {} {
global gdb_prompt decimal vfork_syscalls
with_test_prefix "mid-vfork" {
# Verify that the system supports "catch vfork".
gdb_test "catch vfork" "Catchpoint $decimal \\(vfork\\)" "insert first vfork catchpoint"
gdb_test_multiple "continue" "continue to first vfork catchpoint" {
-re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" {
unsupported "continue to first vfork catchpoint"
return
}
-re ".*Catchpoint $decimal \\(vforked process $decimal\\).*$gdb_prompt $" {
pass "continue to first vfork catchpoint"
}
}
# Check that we now reach vfork return only.
# (The actual syscall used varies by architecture.)
gdb_test "catch syscall" "Catchpoint $decimal \\(any syscall\\)"
check_return_from_syscall "vfork" $vfork_syscalls
# Can we finish?
check_for_program_end
}
}
2016-01-12 21:27:27 +01:00
proc test_catch_syscall_execve {} {
global gdb_prompt decimal
with_test_prefix "execve" {
# Tell the test program we want an execve.
gdb_test_no_output "set do_execve = 1"
# Check for entry/return across the execve, making sure that the
# syscall_state isn't lost when turning into a new process.
insert_catch_syscall_with_arg "execve"
check_continue "execve"
# Continue to main so extended-remote can read files as needed.
# (Otherwise that "Reading" output confuses gdb_continue_to_end.)
gdb_continue "main"
# Now can we finish?
check_for_program_end
}
}
2009-10-31 07:00:13 +01:00
proc test_catch_syscall_fail_nodatadir {} {
2013-10-09 16:31:35 +02:00
with_test_prefix "fail no datadir" {
# Sanitizing.
delete_breakpoints
2009-10-31 07:00:13 +01:00
2013-10-09 16:31:35 +02:00
# Make sure GDB doesn't load the syscalls xml from the system
# data directory.
2014-05-16 21:15:10 +02:00
gdb_test "set data-directory /the/path/to/nowhere" \
"Warning: /the/path/to/nowhere: .*"
2009-11-22 23:57:24 +01:00
2013-10-09 16:31:35 +02:00
# Testing to see if we receive a warning when calling "catch
# syscall" without XML support (without datadir).
set thistest "catch syscall displays a warning when there is no XML support"
gdb_test "catch syscall" \
"warning: Could not load the syscall XML file.*warning: GDB will not be able to display syscall names nor to verify if.*any provided syscall numbers are valid.*Catchpoint .*(syscall).*" \
$thistest
2009-10-31 07:00:13 +01:00
2013-10-09 16:31:35 +02:00
# Since the catchpoint was set, we must check if it's present
# in "info breakpoints" output.
check_info_bp_any_syscall
2009-10-31 07:00:13 +01:00
2013-10-09 16:31:35 +02:00
# Sanitizing.
delete_breakpoints
}
2009-10-31 07:00:13 +01:00
}
2016-07-23 23:38:24 +02:00
proc test_catch_syscall_group {} {
global decimal
set sysnum "\\\[${decimal}\\\]"
gdb_test "catch syscall g:process" \
"Catchpoint $decimal \\(syscalls (\'(clone|fork|execve|exit)\' $sysnum)+.*" \
"set catchpoint on a group of syscalls"
gdb_test "catch syscall group:process read" \
"Catchpoint $decimal \\(syscalls (\'(clone|fork|execve|exit)\' $sysnum)+.*read.*\\)" \
"set catchpoints on a group of syscalls and on a single syscall"
gdb_test "catch syscall group:" \
"Unknown syscall group ''\." \
"set catchpoints on an invalid group"
gdb_test "catch syscall g:junk" \
"Unknown syscall group 'junk'\." \
"set catchpoints on an unknown group."
gdb_test "complete catch syscall g:proc" \
"catch syscall g:process" \
"complete catch syscall group with 'g:' prefix"
gdb_test "complete catch syscall group:proc" \
"catch syscall group:process" \
"complete catch syscall group with 'group:' prefix"
gdb_test_sequence "complete catch syscall g" \
"complete catch syscall group suggests 'group:' prefix" {
"group:descriptor" "group:file" "group:ipc" "group:memory"
"group:network" "group:process" "group:signal"
}
}
2009-09-15 05:32:06 +02:00
proc do_syscall_tests {} {
2010-12-07 18:26:06 +01:00
# NOTE: We don't have to point gdb at the correct data-directory.
# For the build tree that is handled by INTERNAL_GDBFLAGS.
2009-09-15 05:32:06 +02:00
# Verify that the 'catch syscall' help is available
set thistest "help catch syscall"
gdb_test "help catch syscall" "Catch system calls.*" $thistest
# Try to set a catchpoint to a nonsense syscall
set thistest "catch syscall to a nonsense syscall is prohibited"
gdb_test "catch syscall nonsense_syscall" "Unknown syscall name .*" $thistest
2012-11-02 20:05:12 +01:00
# Regression test for syscall completer bug.
gdb_test "complete catch syscall close chroo" \
"catch syscall close chroot" \
"complete catch syscall with multiple words"
2009-09-15 05:32:06 +02:00
# Testing the 'catch syscall' command without arguments.
# This test should catch any syscalls.
if [runto_main] then { test_catch_syscall_without_args }
# Testing the 'catch syscall' command with arguments.
# This test should only catch the specified syscall.
if [runto_main] then { test_catch_syscall_with_args }
# Testing the 'catch syscall' command with many arguments.
# This test should catch $all_syscalls.
if [runto_main] then { test_catch_syscall_with_many_args }
# Testing the 'catch syscall' command with WRONG arguments.
# This test should not trigger any catchpoints.
if [runto_main] then { test_catch_syscall_with_wrong_args }
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
# Testing the 'catch syscall' command during a restart of
2009-09-15 05:32:06 +02:00
# the inferior.
if [runto_main] then { test_catch_syscall_restarting_inferior }
Partial fix for PR breakpoints/10737: Make syscall info be per-arch instead of global
This patch intends to partially fix PR breakpoints/10737, which is
about making the syscall information (for the "catch syscall" command)
be per-arch, instead of global. This is not a full fix because of the
other issues pointed by Pedro here:
<https://sourceware.org/bugzilla/show_bug.cgi?id=10737#c5>
However, I consider it a good step towards the real fix. It will also
help me fix <https://sourceware.org/bugzilla/show_bug.cgi?id=17402>.
What this patch does, basically, is move the "syscalls_info"
struct to gdbarch. Currently, the syscall information is stored in a
global variable inside gdb/xml-syscall.c, which means that there is no
easy way to correlate this info with the current target or
architecture being used, for example. This causes strange behaviors,
because the syscall info is not re-read when the arch changes. For
example, if you put a syscall catchpoint in syscall 5 on i386 (syscall
open), and then load a x86_64 program on GDB and put the same syscall
5 there (fstat on x86_64), you will still see that GDB tells you that
it is catching "open", even though it is not. With this patch, GDB
correctly says that it will be catching fstat syscalls.
(gdb) set architecture i386
The target architecture is assumed to be i386
(gdb) catch syscall 5
Catchpoint 1 (syscall 'open' [5])
(gdb) set architecture i386:x86-64
The target architecture is assumed to be i386:x86-64
(gdb) catch syscall 5
Catchpoint 2 (syscall 'open' [5])
But with the patch:
(gdb) set architecture i386
The target architecture is assumed to be i386
(gdb) catch syscall 5
Catchpoint 1 (syscall 'open' [5])
(gdb) set architecture i386:x86-64
The target architecture is assumed to be i386:x86-64
(gdb) catch syscall 5
Catchpoint 2 (syscall 'fstat' [5])
As I said, there are still some problems on the "catch syscall"
mechanism, because (for example) the user should be able to "catch
syscall open" on i386, and then expect "open" to be caught also on
x86_64. Currently, it doesn't work. I intend to work on this later.
gdb/
2014-11-20 Sergio Durigan Junior <sergiodj@redhat.com>
PR breakpoints/10737
* amd64-linux-tdep.c (amd64_linux_init_abi_common): Adjust call to
set_xml_syscall_file_name to provide gdbarch.
* arm-linux-tdep.c (arm_linux_init_abi): Likewise.
* bfin-linux-tdep.c (bfin_linux_init_abi): Likewise.
* breakpoint.c (print_it_catch_syscall): Adjust call to
get_syscall_by_number to provide gdbarch.
(print_one_catch_syscall): Likewise.
(print_mention_catch_syscall): Likewise.
(print_recreate_catch_syscall): Likewise.
(catch_syscall_split_args): Adjust calls to get_syscall_by_number
and get_syscall_by_name to provide gdbarch.
(catch_syscall_completer): Adjust call to get_syscall_names to
provide gdbarch.
* gdbarch.c: Regenerate.
* gdbarch.h: Likewise.
* gdbarch.sh: Forward declare "struct syscalls_info".
(xml_syscall_file): New variable.
(syscalls_info): Likewise.
* i386-linux-tdep.c (i386_linux_init_abi): Adjust call to
set_xml_syscall_file_name to provide gdbarch.
* mips-linux-tdep.c (mips_linux_init_abi): Likewise.
* ppc-linux-tdep.c (ppc_linux_init_abi): Likewise.
* s390-linux-tdep.c (s390_gdbarch_init): Likewise.
* sparc-linux-tdep.c (sparc32_linux_init_abi): Likewise.
* sparc64-linux-tdep.c (sparc64_linux_init_abi): Likewise.
* xml-syscall.c: Include gdbarch.h.
(set_xml_syscall_file_name): Accept gdbarch parameter.
(get_syscall_by_number): Likewise.
(get_syscall_by_name): Likewise.
(get_syscall_names): Likewise.
(my_gdb_datadir): Delete global variable.
(struct syscalls_info) <my_gdb_datadir>: New variable.
(struct syscalls_info) <sysinfo>: Rename variable to
"syscalls_info".
(sysinfo): Delete global variable.
(have_initialized_sysinfo): Likewise.
(xml_syscall_file): Likewise.
(sysinfo_free_syscalls_desc): Rename to...
(syscalls_info_free_syscalls_desc): ... this.
(free_syscalls_info): Rename "sysinfo" to "syscalls_info". Adjust
code to the new layout of "struct syscalls_info".
(make_cleanup_free_syscalls_info): Rename parameter "sysinfo" to
"syscalls_info".
(syscall_create_syscall_desc): Likewise.
(syscall_start_syscall): Likewise.
(syscall_parse_xml): Likewise.
(xml_init_syscalls_info): Likewise. Drop "const" from return value.
(init_sysinfo): Rename to...
(init_syscalls_info): ...this. Add gdbarch as a parameter.
Adjust function to deal with gdbarch.
(xml_get_syscall_number): Delete parameter sysinfo. Accept
gdbarch as a parameter. Adjust code.
(xml_get_syscall_name): Likewise.
(xml_list_of_syscalls): Likewise.
(set_xml_syscall_file_name): Accept gdbarch as parameter.
(get_syscall_by_number): Likewise.
(get_syscall_by_name): Likewise.
(get_syscall_names): Likewise.
* xml-syscall.h (set_xml_syscall_file_name): Likewise.
(get_syscall_by_number): Likewise.
(get_syscall_by_name): Likewise.
(get_syscall_names): Likewise.
gdb/testsuite/
2014-11-20 Sergio Durigan Junior <sergiodj@redhat.com>
PR breakpoints/10737
* gdb.base/catch-syscall.exp (do_syscall_tests): Call
test_catch_syscall_multi_arch.
(test_catch_syscall_multi_arch): New function.
2014-11-20 18:28:18 +01:00
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
# Testing the 'catch syscall' command toggling off past a
# syscall return, then resuming entry/return as normal.
if [runto_main] then { test_catch_syscall_skipping_return }
# Testing the 'catch syscall' command starting mid-vfork.
if [runto_main] then { test_catch_syscall_mid_vfork }
2016-01-12 21:27:27 +01:00
# Testing that 'catch syscall' entry/return tracks across execve.
if [runto_main] then { test_catch_syscall_execve }
Partial fix for PR breakpoints/10737: Make syscall info be per-arch instead of global
This patch intends to partially fix PR breakpoints/10737, which is
about making the syscall information (for the "catch syscall" command)
be per-arch, instead of global. This is not a full fix because of the
other issues pointed by Pedro here:
<https://sourceware.org/bugzilla/show_bug.cgi?id=10737#c5>
However, I consider it a good step towards the real fix. It will also
help me fix <https://sourceware.org/bugzilla/show_bug.cgi?id=17402>.
What this patch does, basically, is move the "syscalls_info"
struct to gdbarch. Currently, the syscall information is stored in a
global variable inside gdb/xml-syscall.c, which means that there is no
easy way to correlate this info with the current target or
architecture being used, for example. This causes strange behaviors,
because the syscall info is not re-read when the arch changes. For
example, if you put a syscall catchpoint in syscall 5 on i386 (syscall
open), and then load a x86_64 program on GDB and put the same syscall
5 there (fstat on x86_64), you will still see that GDB tells you that
it is catching "open", even though it is not. With this patch, GDB
correctly says that it will be catching fstat syscalls.
(gdb) set architecture i386
The target architecture is assumed to be i386
(gdb) catch syscall 5
Catchpoint 1 (syscall 'open' [5])
(gdb) set architecture i386:x86-64
The target architecture is assumed to be i386:x86-64
(gdb) catch syscall 5
Catchpoint 2 (syscall 'open' [5])
But with the patch:
(gdb) set architecture i386
The target architecture is assumed to be i386
(gdb) catch syscall 5
Catchpoint 1 (syscall 'open' [5])
(gdb) set architecture i386:x86-64
The target architecture is assumed to be i386:x86-64
(gdb) catch syscall 5
Catchpoint 2 (syscall 'fstat' [5])
As I said, there are still some problems on the "catch syscall"
mechanism, because (for example) the user should be able to "catch
syscall open" on i386, and then expect "open" to be caught also on
x86_64. Currently, it doesn't work. I intend to work on this later.
gdb/
2014-11-20 Sergio Durigan Junior <sergiodj@redhat.com>
PR breakpoints/10737
* amd64-linux-tdep.c (amd64_linux_init_abi_common): Adjust call to
set_xml_syscall_file_name to provide gdbarch.
* arm-linux-tdep.c (arm_linux_init_abi): Likewise.
* bfin-linux-tdep.c (bfin_linux_init_abi): Likewise.
* breakpoint.c (print_it_catch_syscall): Adjust call to
get_syscall_by_number to provide gdbarch.
(print_one_catch_syscall): Likewise.
(print_mention_catch_syscall): Likewise.
(print_recreate_catch_syscall): Likewise.
(catch_syscall_split_args): Adjust calls to get_syscall_by_number
and get_syscall_by_name to provide gdbarch.
(catch_syscall_completer): Adjust call to get_syscall_names to
provide gdbarch.
* gdbarch.c: Regenerate.
* gdbarch.h: Likewise.
* gdbarch.sh: Forward declare "struct syscalls_info".
(xml_syscall_file): New variable.
(syscalls_info): Likewise.
* i386-linux-tdep.c (i386_linux_init_abi): Adjust call to
set_xml_syscall_file_name to provide gdbarch.
* mips-linux-tdep.c (mips_linux_init_abi): Likewise.
* ppc-linux-tdep.c (ppc_linux_init_abi): Likewise.
* s390-linux-tdep.c (s390_gdbarch_init): Likewise.
* sparc-linux-tdep.c (sparc32_linux_init_abi): Likewise.
* sparc64-linux-tdep.c (sparc64_linux_init_abi): Likewise.
* xml-syscall.c: Include gdbarch.h.
(set_xml_syscall_file_name): Accept gdbarch parameter.
(get_syscall_by_number): Likewise.
(get_syscall_by_name): Likewise.
(get_syscall_names): Likewise.
(my_gdb_datadir): Delete global variable.
(struct syscalls_info) <my_gdb_datadir>: New variable.
(struct syscalls_info) <sysinfo>: Rename variable to
"syscalls_info".
(sysinfo): Delete global variable.
(have_initialized_sysinfo): Likewise.
(xml_syscall_file): Likewise.
(sysinfo_free_syscalls_desc): Rename to...
(syscalls_info_free_syscalls_desc): ... this.
(free_syscalls_info): Rename "sysinfo" to "syscalls_info". Adjust
code to the new layout of "struct syscalls_info".
(make_cleanup_free_syscalls_info): Rename parameter "sysinfo" to
"syscalls_info".
(syscall_create_syscall_desc): Likewise.
(syscall_start_syscall): Likewise.
(syscall_parse_xml): Likewise.
(xml_init_syscalls_info): Likewise. Drop "const" from return value.
(init_sysinfo): Rename to...
(init_syscalls_info): ...this. Add gdbarch as a parameter.
Adjust function to deal with gdbarch.
(xml_get_syscall_number): Delete parameter sysinfo. Accept
gdbarch as a parameter. Adjust code.
(xml_get_syscall_name): Likewise.
(xml_list_of_syscalls): Likewise.
(set_xml_syscall_file_name): Accept gdbarch as parameter.
(get_syscall_by_number): Likewise.
(get_syscall_by_name): Likewise.
(get_syscall_names): Likewise.
* xml-syscall.h (set_xml_syscall_file_name): Likewise.
(get_syscall_by_number): Likewise.
(get_syscall_by_name): Likewise.
(get_syscall_names): Likewise.
gdb/testsuite/
2014-11-20 Sergio Durigan Junior <sergiodj@redhat.com>
PR breakpoints/10737
* gdb.base/catch-syscall.exp (do_syscall_tests): Call
test_catch_syscall_multi_arch.
(test_catch_syscall_multi_arch): New function.
2014-11-20 18:28:18 +01:00
# Testing if the 'catch syscall' command works when switching to
# different architectures on-the-fly (PR gdb/10737).
if [runto_main] then { test_catch_syscall_multi_arch }
2016-07-23 23:38:24 +02:00
# Testing the 'catch' syscall command for a group of syscalls.
if [runto_main] then { test_catch_syscall_group }
2009-09-15 05:32:06 +02:00
}
proc test_catch_syscall_without_args_noxml {} {
2013-10-09 16:31:35 +02:00
with_test_prefix "without args noxml" {
# We will need the syscall names even not using it because we
# need to know know many syscalls are in the example file.
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
global decimal all_syscalls last_syscall_number unknown_syscall_number all_syscalls_numbers
2013-10-09 16:31:35 +02:00
delete_breakpoints
gdb_test "catch syscall" "Catchpoint .*(syscall).*"
# Now, we should be able to set a catchpoint, and GDB shall
# not display the warning anymore.
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
foreach name $all_syscalls number $all_syscalls_numbers {
2013-10-09 16:31:35 +02:00
with_test_prefix "$name" {
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
check_continue $number
2013-10-09 16:31:35 +02:00
}
}
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
check_continue "vfork" $decimal
with_test_prefix "ENOSYS" {
check_continue $unknown_syscall_number
}
2013-10-09 16:31:35 +02:00
# At last but not least, we check if the inferior has called
# the last (exit) syscall.
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
check_call_to_syscall $last_syscall_number
2013-10-09 16:31:35 +02:00
delete_breakpoints
2009-09-15 05:32:06 +02:00
}
}
proc test_catch_syscall_with_args_noxml {} {
2013-10-09 16:31:35 +02:00
with_test_prefix "with args noxml" {
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
global all_syscalls_numbers
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
delete_breakpoints
2009-09-15 05:32:06 +02:00
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
# Inserting all syscalls numbers to be caught
foreach syscall_number $all_syscalls_numbers {
insert_catch_syscall_with_arg $syscall_number
}
2009-09-15 05:32:06 +02:00
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
# Checking that all syscalls are caught.
foreach syscall_number $all_syscalls_numbers {
check_continue $syscall_number
}
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
delete_breakpoints
}
2009-09-15 05:32:06 +02:00
}
proc test_catch_syscall_with_wrong_args_noxml {} {
2013-10-09 16:31:35 +02:00
with_test_prefix "with wrong args noxml" {
delete_breakpoints
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
# Even without XML support, GDB should not accept unknown
# syscall names for the catchpoint.
gdb_test "catch syscall nonsense_syscall" \
"Unknown syscall name .nonsense_syscall.*"
2009-09-15 05:32:06 +02:00
2013-10-09 16:31:35 +02:00
delete_breakpoints
}
2009-09-15 05:32:06 +02:00
}
Partial fix for PR breakpoints/10737: Make syscall info be per-arch instead of global
This patch intends to partially fix PR breakpoints/10737, which is
about making the syscall information (for the "catch syscall" command)
be per-arch, instead of global. This is not a full fix because of the
other issues pointed by Pedro here:
<https://sourceware.org/bugzilla/show_bug.cgi?id=10737#c5>
However, I consider it a good step towards the real fix. It will also
help me fix <https://sourceware.org/bugzilla/show_bug.cgi?id=17402>.
What this patch does, basically, is move the "syscalls_info"
struct to gdbarch. Currently, the syscall information is stored in a
global variable inside gdb/xml-syscall.c, which means that there is no
easy way to correlate this info with the current target or
architecture being used, for example. This causes strange behaviors,
because the syscall info is not re-read when the arch changes. For
example, if you put a syscall catchpoint in syscall 5 on i386 (syscall
open), and then load a x86_64 program on GDB and put the same syscall
5 there (fstat on x86_64), you will still see that GDB tells you that
it is catching "open", even though it is not. With this patch, GDB
correctly says that it will be catching fstat syscalls.
(gdb) set architecture i386
The target architecture is assumed to be i386
(gdb) catch syscall 5
Catchpoint 1 (syscall 'open' [5])
(gdb) set architecture i386:x86-64
The target architecture is assumed to be i386:x86-64
(gdb) catch syscall 5
Catchpoint 2 (syscall 'open' [5])
But with the patch:
(gdb) set architecture i386
The target architecture is assumed to be i386
(gdb) catch syscall 5
Catchpoint 1 (syscall 'open' [5])
(gdb) set architecture i386:x86-64
The target architecture is assumed to be i386:x86-64
(gdb) catch syscall 5
Catchpoint 2 (syscall 'fstat' [5])
As I said, there are still some problems on the "catch syscall"
mechanism, because (for example) the user should be able to "catch
syscall open" on i386, and then expect "open" to be caught also on
x86_64. Currently, it doesn't work. I intend to work on this later.
gdb/
2014-11-20 Sergio Durigan Junior <sergiodj@redhat.com>
PR breakpoints/10737
* amd64-linux-tdep.c (amd64_linux_init_abi_common): Adjust call to
set_xml_syscall_file_name to provide gdbarch.
* arm-linux-tdep.c (arm_linux_init_abi): Likewise.
* bfin-linux-tdep.c (bfin_linux_init_abi): Likewise.
* breakpoint.c (print_it_catch_syscall): Adjust call to
get_syscall_by_number to provide gdbarch.
(print_one_catch_syscall): Likewise.
(print_mention_catch_syscall): Likewise.
(print_recreate_catch_syscall): Likewise.
(catch_syscall_split_args): Adjust calls to get_syscall_by_number
and get_syscall_by_name to provide gdbarch.
(catch_syscall_completer): Adjust call to get_syscall_names to
provide gdbarch.
* gdbarch.c: Regenerate.
* gdbarch.h: Likewise.
* gdbarch.sh: Forward declare "struct syscalls_info".
(xml_syscall_file): New variable.
(syscalls_info): Likewise.
* i386-linux-tdep.c (i386_linux_init_abi): Adjust call to
set_xml_syscall_file_name to provide gdbarch.
* mips-linux-tdep.c (mips_linux_init_abi): Likewise.
* ppc-linux-tdep.c (ppc_linux_init_abi): Likewise.
* s390-linux-tdep.c (s390_gdbarch_init): Likewise.
* sparc-linux-tdep.c (sparc32_linux_init_abi): Likewise.
* sparc64-linux-tdep.c (sparc64_linux_init_abi): Likewise.
* xml-syscall.c: Include gdbarch.h.
(set_xml_syscall_file_name): Accept gdbarch parameter.
(get_syscall_by_number): Likewise.
(get_syscall_by_name): Likewise.
(get_syscall_names): Likewise.
(my_gdb_datadir): Delete global variable.
(struct syscalls_info) <my_gdb_datadir>: New variable.
(struct syscalls_info) <sysinfo>: Rename variable to
"syscalls_info".
(sysinfo): Delete global variable.
(have_initialized_sysinfo): Likewise.
(xml_syscall_file): Likewise.
(sysinfo_free_syscalls_desc): Rename to...
(syscalls_info_free_syscalls_desc): ... this.
(free_syscalls_info): Rename "sysinfo" to "syscalls_info". Adjust
code to the new layout of "struct syscalls_info".
(make_cleanup_free_syscalls_info): Rename parameter "sysinfo" to
"syscalls_info".
(syscall_create_syscall_desc): Likewise.
(syscall_start_syscall): Likewise.
(syscall_parse_xml): Likewise.
(xml_init_syscalls_info): Likewise. Drop "const" from return value.
(init_sysinfo): Rename to...
(init_syscalls_info): ...this. Add gdbarch as a parameter.
Adjust function to deal with gdbarch.
(xml_get_syscall_number): Delete parameter sysinfo. Accept
gdbarch as a parameter. Adjust code.
(xml_get_syscall_name): Likewise.
(xml_list_of_syscalls): Likewise.
(set_xml_syscall_file_name): Accept gdbarch as parameter.
(get_syscall_by_number): Likewise.
(get_syscall_by_name): Likewise.
(get_syscall_names): Likewise.
* xml-syscall.h (set_xml_syscall_file_name): Likewise.
(get_syscall_by_number): Likewise.
(get_syscall_by_name): Likewise.
(get_syscall_names): Likewise.
gdb/testsuite/
2014-11-20 Sergio Durigan Junior <sergiodj@redhat.com>
PR breakpoints/10737
* gdb.base/catch-syscall.exp (do_syscall_tests): Call
test_catch_syscall_multi_arch.
(test_catch_syscall_multi_arch): New function.
2014-11-20 18:28:18 +01:00
proc test_catch_syscall_multi_arch {} {
global decimal binfile
if { [istarget "i*86-*-*"] || [istarget "x86_64-*-*"] } {
set arch1 "i386"
set arch2 "i386:x86-64"
set syscall1_name "exit"
set syscall2_name "write"
set syscall_number 1
} elseif { [istarget "powerpc-*-linux*"] \
|| [istarget "powerpc64-*-linux*"] } {
set arch1 "powerpc:common"
set arch2 "powerpc:common64"
set syscall1_name "openat"
set syscall2_name "unlinkat"
set syscall_number 286
} elseif { [istarget "sparc-*-linux*"] \
|| [istarget "sparc64-*-linux*"] } {
set arch1 "sparc"
set arch2 "sparc:v9"
set syscall1_name "setresuid32"
set syscall2_name "setresuid"
set syscall_number 108
} elseif { [istarget "mips*-linux*"] } {
# MIPS does not use the same numbers for syscalls on 32 and 64
# bits.
verbose "Not testing MIPS for multi-arch syscall support"
return
} elseif { [istarget "arm*-linux*"] } {
# catch syscall supports only 32-bit ARM for now.
verbose "Not testing ARM for multi-arch syscall support"
return
Support catch syscall on aarch64 linux
Hi,
This patch is to support catch syscall on aarch64 linux. We
implement gdbarch method get_syscall_number for aarch64-linux,
and add aarch64-linux.xml file, which looks straightforward, however
the changes to test case doesn't.
First of all, we enable catch-syscall.exp on aarch64-linux target,
but skip the multi_arch testing on current stage. I plan to touch
multi arch debugging on aarch64-linux later.
Then, when I run catch-syscall.exp on aarch64-linux, gcc errors that
SYS_pipe isn't defined. We find that aarch64 kernel only has pipe2
syscall and libc already convert pipe to pipe2. As a result, I change
catch-syscall.c to use SYS_pipe if it is defined, otherwise use
SYS_pipe2 instead. The vector all_syscalls in catch-syscall.exp can't
be pre-determined, so I add a new proc setup_all_syscalls to fill it,
according to the availability of SYS_pipe.
Regression tested on {x86_64, aarch64}-linux x {native, gdbserver}.
gdb:
2015-03-18 Yao Qi <yao.qi@linaro.org>
PR tdep/18107
* aarch64-linux-tdep.c: Include xml-syscall.h
(aarch64_linux_get_syscall_number): New function.
(aarch64_linux_init_abi): Call
set_gdbarch_get_syscall_number.
* syscalls/aarch64-linux.xml: New file.
gdb/testsuite:
2015-03-18 Yao Qi <yao.qi@linaro.org>
PR tdep/18107
* gdb.base/catch-syscall.c [!SYS_pipe] (pipe2_syscall): New
variable.
* gdb.base/catch-syscall.exp: Don't skip it on
aarch64*-*-linux* target. Remove elements in all_syscalls.
(test_catch_syscall_multi_arch): Skip it on aarch64*-linux*
target.
(setup_all_syscalls): New proc.
2015-03-18 11:47:45 +01:00
} elseif { [istarget "aarch64*-linux*"] } {
2015-07-07 17:58:19 +02:00
set arch1 "aarch64"
set arch2 "arm"
set syscall1_name "reboot"
set syscall2_name "_newselect"
set syscall_number 142
Partial fix for PR breakpoints/10737: Make syscall info be per-arch instead of global
This patch intends to partially fix PR breakpoints/10737, which is
about making the syscall information (for the "catch syscall" command)
be per-arch, instead of global. This is not a full fix because of the
other issues pointed by Pedro here:
<https://sourceware.org/bugzilla/show_bug.cgi?id=10737#c5>
However, I consider it a good step towards the real fix. It will also
help me fix <https://sourceware.org/bugzilla/show_bug.cgi?id=17402>.
What this patch does, basically, is move the "syscalls_info"
struct to gdbarch. Currently, the syscall information is stored in a
global variable inside gdb/xml-syscall.c, which means that there is no
easy way to correlate this info with the current target or
architecture being used, for example. This causes strange behaviors,
because the syscall info is not re-read when the arch changes. For
example, if you put a syscall catchpoint in syscall 5 on i386 (syscall
open), and then load a x86_64 program on GDB and put the same syscall
5 there (fstat on x86_64), you will still see that GDB tells you that
it is catching "open", even though it is not. With this patch, GDB
correctly says that it will be catching fstat syscalls.
(gdb) set architecture i386
The target architecture is assumed to be i386
(gdb) catch syscall 5
Catchpoint 1 (syscall 'open' [5])
(gdb) set architecture i386:x86-64
The target architecture is assumed to be i386:x86-64
(gdb) catch syscall 5
Catchpoint 2 (syscall 'open' [5])
But with the patch:
(gdb) set architecture i386
The target architecture is assumed to be i386
(gdb) catch syscall 5
Catchpoint 1 (syscall 'open' [5])
(gdb) set architecture i386:x86-64
The target architecture is assumed to be i386:x86-64
(gdb) catch syscall 5
Catchpoint 2 (syscall 'fstat' [5])
As I said, there are still some problems on the "catch syscall"
mechanism, because (for example) the user should be able to "catch
syscall open" on i386, and then expect "open" to be caught also on
x86_64. Currently, it doesn't work. I intend to work on this later.
gdb/
2014-11-20 Sergio Durigan Junior <sergiodj@redhat.com>
PR breakpoints/10737
* amd64-linux-tdep.c (amd64_linux_init_abi_common): Adjust call to
set_xml_syscall_file_name to provide gdbarch.
* arm-linux-tdep.c (arm_linux_init_abi): Likewise.
* bfin-linux-tdep.c (bfin_linux_init_abi): Likewise.
* breakpoint.c (print_it_catch_syscall): Adjust call to
get_syscall_by_number to provide gdbarch.
(print_one_catch_syscall): Likewise.
(print_mention_catch_syscall): Likewise.
(print_recreate_catch_syscall): Likewise.
(catch_syscall_split_args): Adjust calls to get_syscall_by_number
and get_syscall_by_name to provide gdbarch.
(catch_syscall_completer): Adjust call to get_syscall_names to
provide gdbarch.
* gdbarch.c: Regenerate.
* gdbarch.h: Likewise.
* gdbarch.sh: Forward declare "struct syscalls_info".
(xml_syscall_file): New variable.
(syscalls_info): Likewise.
* i386-linux-tdep.c (i386_linux_init_abi): Adjust call to
set_xml_syscall_file_name to provide gdbarch.
* mips-linux-tdep.c (mips_linux_init_abi): Likewise.
* ppc-linux-tdep.c (ppc_linux_init_abi): Likewise.
* s390-linux-tdep.c (s390_gdbarch_init): Likewise.
* sparc-linux-tdep.c (sparc32_linux_init_abi): Likewise.
* sparc64-linux-tdep.c (sparc64_linux_init_abi): Likewise.
* xml-syscall.c: Include gdbarch.h.
(set_xml_syscall_file_name): Accept gdbarch parameter.
(get_syscall_by_number): Likewise.
(get_syscall_by_name): Likewise.
(get_syscall_names): Likewise.
(my_gdb_datadir): Delete global variable.
(struct syscalls_info) <my_gdb_datadir>: New variable.
(struct syscalls_info) <sysinfo>: Rename variable to
"syscalls_info".
(sysinfo): Delete global variable.
(have_initialized_sysinfo): Likewise.
(xml_syscall_file): Likewise.
(sysinfo_free_syscalls_desc): Rename to...
(syscalls_info_free_syscalls_desc): ... this.
(free_syscalls_info): Rename "sysinfo" to "syscalls_info". Adjust
code to the new layout of "struct syscalls_info".
(make_cleanup_free_syscalls_info): Rename parameter "sysinfo" to
"syscalls_info".
(syscall_create_syscall_desc): Likewise.
(syscall_start_syscall): Likewise.
(syscall_parse_xml): Likewise.
(xml_init_syscalls_info): Likewise. Drop "const" from return value.
(init_sysinfo): Rename to...
(init_syscalls_info): ...this. Add gdbarch as a parameter.
Adjust function to deal with gdbarch.
(xml_get_syscall_number): Delete parameter sysinfo. Accept
gdbarch as a parameter. Adjust code.
(xml_get_syscall_name): Likewise.
(xml_list_of_syscalls): Likewise.
(set_xml_syscall_file_name): Accept gdbarch as parameter.
(get_syscall_by_number): Likewise.
(get_syscall_by_name): Likewise.
(get_syscall_names): Likewise.
* xml-syscall.h (set_xml_syscall_file_name): Likewise.
(get_syscall_by_number): Likewise.
(get_syscall_by_name): Likewise.
(get_syscall_names): Likewise.
gdb/testsuite/
2014-11-20 Sergio Durigan Junior <sergiodj@redhat.com>
PR breakpoints/10737
* gdb.base/catch-syscall.exp (do_syscall_tests): Call
test_catch_syscall_multi_arch.
(test_catch_syscall_multi_arch): New function.
2014-11-20 18:28:18 +01:00
} elseif { [istarget "s390*-linux*"] } {
2015-03-04 10:40:40 +01:00
set arch1 "s390:31-bit"
Partial fix for PR breakpoints/10737: Make syscall info be per-arch instead of global
This patch intends to partially fix PR breakpoints/10737, which is
about making the syscall information (for the "catch syscall" command)
be per-arch, instead of global. This is not a full fix because of the
other issues pointed by Pedro here:
<https://sourceware.org/bugzilla/show_bug.cgi?id=10737#c5>
However, I consider it a good step towards the real fix. It will also
help me fix <https://sourceware.org/bugzilla/show_bug.cgi?id=17402>.
What this patch does, basically, is move the "syscalls_info"
struct to gdbarch. Currently, the syscall information is stored in a
global variable inside gdb/xml-syscall.c, which means that there is no
easy way to correlate this info with the current target or
architecture being used, for example. This causes strange behaviors,
because the syscall info is not re-read when the arch changes. For
example, if you put a syscall catchpoint in syscall 5 on i386 (syscall
open), and then load a x86_64 program on GDB and put the same syscall
5 there (fstat on x86_64), you will still see that GDB tells you that
it is catching "open", even though it is not. With this patch, GDB
correctly says that it will be catching fstat syscalls.
(gdb) set architecture i386
The target architecture is assumed to be i386
(gdb) catch syscall 5
Catchpoint 1 (syscall 'open' [5])
(gdb) set architecture i386:x86-64
The target architecture is assumed to be i386:x86-64
(gdb) catch syscall 5
Catchpoint 2 (syscall 'open' [5])
But with the patch:
(gdb) set architecture i386
The target architecture is assumed to be i386
(gdb) catch syscall 5
Catchpoint 1 (syscall 'open' [5])
(gdb) set architecture i386:x86-64
The target architecture is assumed to be i386:x86-64
(gdb) catch syscall 5
Catchpoint 2 (syscall 'fstat' [5])
As I said, there are still some problems on the "catch syscall"
mechanism, because (for example) the user should be able to "catch
syscall open" on i386, and then expect "open" to be caught also on
x86_64. Currently, it doesn't work. I intend to work on this later.
gdb/
2014-11-20 Sergio Durigan Junior <sergiodj@redhat.com>
PR breakpoints/10737
* amd64-linux-tdep.c (amd64_linux_init_abi_common): Adjust call to
set_xml_syscall_file_name to provide gdbarch.
* arm-linux-tdep.c (arm_linux_init_abi): Likewise.
* bfin-linux-tdep.c (bfin_linux_init_abi): Likewise.
* breakpoint.c (print_it_catch_syscall): Adjust call to
get_syscall_by_number to provide gdbarch.
(print_one_catch_syscall): Likewise.
(print_mention_catch_syscall): Likewise.
(print_recreate_catch_syscall): Likewise.
(catch_syscall_split_args): Adjust calls to get_syscall_by_number
and get_syscall_by_name to provide gdbarch.
(catch_syscall_completer): Adjust call to get_syscall_names to
provide gdbarch.
* gdbarch.c: Regenerate.
* gdbarch.h: Likewise.
* gdbarch.sh: Forward declare "struct syscalls_info".
(xml_syscall_file): New variable.
(syscalls_info): Likewise.
* i386-linux-tdep.c (i386_linux_init_abi): Adjust call to
set_xml_syscall_file_name to provide gdbarch.
* mips-linux-tdep.c (mips_linux_init_abi): Likewise.
* ppc-linux-tdep.c (ppc_linux_init_abi): Likewise.
* s390-linux-tdep.c (s390_gdbarch_init): Likewise.
* sparc-linux-tdep.c (sparc32_linux_init_abi): Likewise.
* sparc64-linux-tdep.c (sparc64_linux_init_abi): Likewise.
* xml-syscall.c: Include gdbarch.h.
(set_xml_syscall_file_name): Accept gdbarch parameter.
(get_syscall_by_number): Likewise.
(get_syscall_by_name): Likewise.
(get_syscall_names): Likewise.
(my_gdb_datadir): Delete global variable.
(struct syscalls_info) <my_gdb_datadir>: New variable.
(struct syscalls_info) <sysinfo>: Rename variable to
"syscalls_info".
(sysinfo): Delete global variable.
(have_initialized_sysinfo): Likewise.
(xml_syscall_file): Likewise.
(sysinfo_free_syscalls_desc): Rename to...
(syscalls_info_free_syscalls_desc): ... this.
(free_syscalls_info): Rename "sysinfo" to "syscalls_info". Adjust
code to the new layout of "struct syscalls_info".
(make_cleanup_free_syscalls_info): Rename parameter "sysinfo" to
"syscalls_info".
(syscall_create_syscall_desc): Likewise.
(syscall_start_syscall): Likewise.
(syscall_parse_xml): Likewise.
(xml_init_syscalls_info): Likewise. Drop "const" from return value.
(init_sysinfo): Rename to...
(init_syscalls_info): ...this. Add gdbarch as a parameter.
Adjust function to deal with gdbarch.
(xml_get_syscall_number): Delete parameter sysinfo. Accept
gdbarch as a parameter. Adjust code.
(xml_get_syscall_name): Likewise.
(xml_list_of_syscalls): Likewise.
(set_xml_syscall_file_name): Accept gdbarch as parameter.
(get_syscall_by_number): Likewise.
(get_syscall_by_name): Likewise.
(get_syscall_names): Likewise.
* xml-syscall.h (set_xml_syscall_file_name): Likewise.
(get_syscall_by_number): Likewise.
(get_syscall_by_name): Likewise.
(get_syscall_names): Likewise.
gdb/testsuite/
2014-11-20 Sergio Durigan Junior <sergiodj@redhat.com>
PR breakpoints/10737
* gdb.base/catch-syscall.exp (do_syscall_tests): Call
test_catch_syscall_multi_arch.
(test_catch_syscall_multi_arch): New function.
2014-11-20 18:28:18 +01:00
set arch2 "s390:64-bit"
set syscall1_name "_newselect"
set syscall2_name "select"
set syscall_number 142
}
with_test_prefix "multiple targets" {
# We are not interested in loading any binary here, and in
# some systems (PowerPC, for example), if we load a binary
# there is no way to set other architecture.
gdb_exit
gdb_start
gdb_test "set architecture $arch1" \
"The target architecture is assumed to be $arch1" \
"set arch to $arch1"
gdb_test "catch syscall $syscall_number" \
"Catchpoint $decimal \\(syscall .${syscall1_name}. \\\[${syscall_number}\\\]\\)" \
"insert catch syscall on syscall $syscall_number -- $syscall1_name on $arch1"
gdb_test "set architecture $arch2" \
"The target architecture is assumed to be $arch2" \
"set arch to $arch2"
gdb_test "catch syscall $syscall_number" \
"Catchpoint $decimal \\(syscall .${syscall2_name}. \\\[${syscall_number}\\\]\\)" \
"insert catch syscall on syscall $syscall_number -- $syscall2_name on $arch2"
clean_restart $binfile
}
}
2009-09-15 05:32:06 +02:00
proc do_syscall_tests_without_xml {} {
2009-11-22 23:57:24 +01:00
# Make sure GDB doesn't load the syscalls xml from the system data
# directory.
2014-05-16 21:15:10 +02:00
gdb_test "set data-directory /the/path/to/nowhere" \
"Warning: /the/path/to/nowhere: .*"
2009-09-15 05:32:06 +02:00
2009-10-31 07:00:13 +01:00
# Let's test if we can catch syscalls without XML support.
2009-09-15 05:32:06 +02:00
# We should succeed, but GDB is not supposed to print syscall names.
if [runto_main] then { test_catch_syscall_without_args_noxml }
# The only valid argument "catch syscall" should accept is the
# syscall number, and not the name (since it can't translate a
# name to a number).
if [runto_main] then { test_catch_syscall_with_args_noxml }
# Now, we'll try to provide a syscall name (valid or not) to the command,
# and expect it to fail.
if [runto_main] then { test_catch_syscall_with_wrong_args_noxml }
}
# This procedure fills the vector "all_syscalls_numbers" with the proper
# numbers for the used syscalls according to the architecture.
proc fill_all_syscalls_numbers {} {
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
global all_syscalls_numbers last_syscall_number unknown_syscall_number all_syscalls
Fix PR breakpoints/16297: catch syscall with syscall 0
Code rationale
==============
by: Gabriel Krisman Bertazi
This is a fix for bug 16297. The problem occurs when the user attempts
to catch any syscall 0 (such as syscall read on Linux/x86_64). GDB was
not able to catch the syscall and was missing the breakpoint.
Now, breakpoint_hit_catch_syscall returns immediately when it finds the
correct syscall number, avoiding a following check for the end of the
search vector, that returns a no hit if the syscall number was zero.
Testcase rationale
==================
by: Sergio Durigan Junior
This testcase is a little difficult to write. By doing a quick
inspection at the Linux source, one can see that, in many targets, the
syscall number 0 is restart_syscall, which is forbidden to be called
from userspace. Therefore, on many targets, there's just no way to test
this safely.
My decision was to take the simpler route and just adds the "read"
syscall on the default test. Its number on x86_64 is zero, which is
"good enough" since many people here do their tests on x86_64 anyway and
it is a popular architecture.
However, there was another little gotcha. When using "read" passing 0
as the third parameter (i.e., asking it to read 0 bytes), current libc
implementations could choose not to effectively call the syscall.
Therefore, the best solution was to create a temporary pipe, write 1
byte into it, and then read this byte from it.
gdb/ChangeLog
2013-12-19 Gabriel Krisman Bertazi <gabriel@krisman.be>
PR breakpoints/16297
* breakpoint.c (breakpoint_hit_catch_syscall): Return immediately
when expected syscall is hit.
gdb/testsuite/ChangeLog
2013-12-19 Sergio Durigan Junior <sergiodj@redhat.com>
PR breakpoints/16297
* gdb.base/catch-syscall.c (read_syscall, pipe_syscall)
(write_syscall): New variables.
(main): Create a pipe, write 1 byte in it, and read 1 byte from
it.
* gdb.base/catch-syscall.exp (all_syscalls): Include "pipe,
"write" and "read" syscalls.
(fill_all_syscalls_numbers): Improve the way to obtain syscalls
numbers.
2013-12-19 20:01:49 +01:00
foreach syscall $all_syscalls {
lappend all_syscalls_numbers [get_integer_valueof "${syscall}_syscall" -1]
}
2009-09-15 05:32:06 +02:00
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
set last_syscall_number [get_integer_valueof "exit_group_syscall" -1]
gdb: Improve syscall entry/return tracking on Linux
The existing logic was simply to flip syscall entry/return state when a
syscall trap was seen, and even then only with active 'catch syscall'.
That can get out of sync if 'catch syscall' is toggled at odd times.
This patch updates the entry/return state for all syscall traps,
regardless of catching state, and also updates known syscall state for
other kinds of traps. Almost all PTRACE_EVENT stops are delivered from
the middle of a syscall, so this can act like an entry. Every other
kind of ptrace stop is only delivered outside of syscall event pairs, so
marking them ignored ensures the next syscall trap looks like an entry.
Three new test scenarios are added to catch-syscall.exp:
- Disable 'catch syscall' from an entry to deliberately miss the return
event, then re-enable to make sure a new entry is recognized.
- Enable 'catch syscall' for the first time from a vfork event, which is
a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next
syscall event is recognized as the return.
- Make sure entry and return are recognized for an ENOSYS syscall. This
is to defeat a common x86 hack that uses the pre-filled ENOSYS return
value as a sign of being on the entry side.
gdb/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* linux-nat.c (linux_handle_syscall_trap): Always update entry/
return state, even when not actively catching syscalls at all.
(linux_handle_extended_wait): Mark syscall_state like an entry.
(wait_lwp): Set syscall_state ignored for other traps.
(linux_nat_filter_event): Likewise.
gdb/testsuite/ChangeLog:
2015-10-19 Josh Stone <jistone@redhat.com>
* gdb.base/catch-syscall.c: Include <sched.h>.
(unknown_syscall): New variable.
(main): Trigger a vfork and an unknown syscall.
* gdb.base/catch-syscall.exp (vfork_syscalls): New variable.
(unknown_syscall_number): Likewise.
(check_call_to_syscall): Accept an optional syscall pattern.
(check_return_from_syscall): Likewise.
(check_continue): Likewise.
(test_catch_syscall_without_args): Check for vfork and ENOSYS.
(test_catch_syscall_skipping_return): New test toggling off 'catch
syscall' to step over the syscall return, then toggling back on.
(test_catch_syscall_mid_vfork): New test turning on 'catch syscall'
during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall.
(do_syscall_tests): Call test_catch_syscall_without_args and
test_catch_syscall_mid_vfork.
(test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS.
(fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
set unknown_syscall_number [get_integer_valueof "unknown_syscall" -1]
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
}
2009-09-15 05:32:06 +02:00
Support catch syscall on aarch64 linux
Hi,
This patch is to support catch syscall on aarch64 linux. We
implement gdbarch method get_syscall_number for aarch64-linux,
and add aarch64-linux.xml file, which looks straightforward, however
the changes to test case doesn't.
First of all, we enable catch-syscall.exp on aarch64-linux target,
but skip the multi_arch testing on current stage. I plan to touch
multi arch debugging on aarch64-linux later.
Then, when I run catch-syscall.exp on aarch64-linux, gcc errors that
SYS_pipe isn't defined. We find that aarch64 kernel only has pipe2
syscall and libc already convert pipe to pipe2. As a result, I change
catch-syscall.c to use SYS_pipe if it is defined, otherwise use
SYS_pipe2 instead. The vector all_syscalls in catch-syscall.exp can't
be pre-determined, so I add a new proc setup_all_syscalls to fill it,
according to the availability of SYS_pipe.
Regression tested on {x86_64, aarch64}-linux x {native, gdbserver}.
gdb:
2015-03-18 Yao Qi <yao.qi@linaro.org>
PR tdep/18107
* aarch64-linux-tdep.c: Include xml-syscall.h
(aarch64_linux_get_syscall_number): New function.
(aarch64_linux_init_abi): Call
set_gdbarch_get_syscall_number.
* syscalls/aarch64-linux.xml: New file.
gdb/testsuite:
2015-03-18 Yao Qi <yao.qi@linaro.org>
PR tdep/18107
* gdb.base/catch-syscall.c [!SYS_pipe] (pipe2_syscall): New
variable.
* gdb.base/catch-syscall.exp: Don't skip it on
aarch64*-*-linux* target. Remove elements in all_syscalls.
(test_catch_syscall_multi_arch): Skip it on aarch64*-linux*
target.
(setup_all_syscalls): New proc.
2015-03-18 11:47:45 +01:00
# Set up the vector all_syscalls.
proc setup_all_syscalls {} {
global all_syscalls
global gdb_prompt
# They are ordered according to the file, so do not change this.
lappend all_syscalls "close"
lappend all_syscalls "chroot"
# SYS_pipe doesn't exist on aarch64 kernel.
set test "check SYS_pipe"
gdb_test_multiple "p pipe_syscall" $test {
-re " = .*$gdb_prompt $" {
pass $test
lappend all_syscalls "pipe"
}
-re "No symbol .*$gdb_prompt $" {
pass $test
# SYS_pipe isn't defined, use SYS_pipe2 instead.
lappend all_syscalls "pipe2"
}
}
lappend all_syscalls "write"
lappend all_syscalls "read"
}
setup_all_syscalls
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
# Fill all the syscalls numbers before starting anything.
fill_all_syscalls_numbers
2009-09-15 05:32:06 +02:00
# Execute the tests, using XML support
2015-07-24 22:46:49 +02:00
gdb_exit
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
if { ![gdb_skip_xml_test] } {
clean_restart $binfile
2009-10-31 07:00:13 +01:00
do_syscall_tests
# Now, we have to see if GDB displays a warning when we
# don't set the data-directory but try to use catch syscall
# anyway. For that, we must restart GDB first.
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
clean_restart $binfile
2009-10-31 07:00:13 +01:00
test_catch_syscall_fail_nodatadir
}
2009-09-15 05:32:06 +02:00
# Restart gdb
Improve and fix catch-syscall.exp
While fixing another bug, I found that the current
gdb.base/catch-syscall.exp is kind of messy, could use some
improvements, and is not correctly testing some things.
I've made the following patch to address all the issues I found. On the
organization side, it does a cleanup and removes unecessary imports of
gdb_prompt, uses prepare_for_testing and clean_restart where needed, and
fixes some comments. The testcase was also not correctly testing
catching syscalls using only numbers, or catching many syscalls at
once. I fixed that.
The patch also uses a new method for obtaining the syscalls numbers: it
relies on the C source file to get them, via <sys/syscall.h> and SYS_*
macros. This makes the .exp file simpler because there is no need to
include target conditionals there.
I tested this on x86_64 Fedora 18.
gdb/testsuite/ChangeLog:
2013-12-18 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/catch-syscall.c: Include <sys/syscall.h>.
(close_syscall, chroot_syscall, exit_group_syscall): New
variables.
* gdb.base/catch-syscall.exp: Replace gdb_compile by
prepare_for_testing. Call fill_all_syscalls_numbers before
starting. Replace gdb_exit, gdb_start, gdb_reinitialize_dir and
gdb_load by clean_restart.
(check_info_bp_any_syscall, check_info_bp_specific_syscall)
(check_info_bp_many_syscalls): Remove global gdb_prompt.
(check_call_to_syscall): Likewise. Add global decimal. Improve
testing regex.
(check_return_from_syscall): Likewise.
(check_continue, insert_catch_syscall_with_arg): Remove global
gdb_prompt.
(insert_catch_syscall_with_many_args): Likewise. Add global
decimal. Fix $filter_str. Improve testing regex.
(check_for_program_end): Remove global gdb_prompt.
(test_catch_syscall_without_args): Likewise. Add global decimal.
Improve testing regex.
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
(test_catch_syscall_restarting_inferior)
(test_catch_syscall_fail_nodatadir): Remove global gdb_prompt.
(do_syscall_tests): Likewise. Remove global srcdir.
(test_catch_syscall_without_args_noxml): Remove global gdb_prompt.
Add global last_syscall_number. Test for the exact syscall number
to be caught.
(test_catch_syscall_with_args_noxml): Remove global gdb_prompt.
Add global all_syscalls_numbers. Test each syscall number to be
caught, instead of only testing "close".
(test_catch_syscall_with_wrong_args_noxml): Remove global gdb_prompt.
(do_syscall_tests_without_xml): Likewise. Remove global srcdir.
Remove stale comment.
(fill_all_syscalls_numbers): Add global last_syscall_number. Fill
the correct syscall numbers using information from the inferior.
2013-12-18 23:19:01 +01:00
clean_restart $binfile
2009-09-15 05:32:06 +02:00
# Execute the tests, without XML support. In this case, GDB will
# only display syscall numbers, and not syscall names.
do_syscall_tests_without_xml