aboutsummaryrefslogtreecommitdiff
path: root/gdb/nat
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2022-01-15 23:25:59 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2022-02-10 20:10:12 -0500
commita288518611dbda5cfae8894d532cf1040cb1b6c2 (patch)
tree8a08bcc229f42cc2f6e64f2045d5225dcaabb06b /gdb/nat
parenta9dce16586c147c024b49604aa0603d772372f31 (diff)
downloadbinutils-a288518611dbda5cfae8894d532cf1040cb1b6c2.zip
binutils-a288518611dbda5cfae8894d532cf1040cb1b6c2.tar.gz
binutils-a288518611dbda5cfae8894d532cf1040cb1b6c2.tar.bz2
gdb/linux: remove ptrace support check for exec, fork, vfork, vforkdone, clone, sysgood
I think it's safe to remove checking support for these ptrace features, they have all been added in what is now ancient times (around the beginning of Linux 2.6). This allows removing a bit of complexity in linux-nat.c and nat/linux-ptrace.c. It also allows saving one extra fork every time we start debugging on Linux: linux_check_ptrace_features forks a child process to test if some ptrace features are supported. That child process forks a grand-child, to test whether ptrace reports an event for the fork by the child. This is no longer needed, if we assume the kernel supports reporting forks. PTRACE_O_TRACEVFORKDONE was introduced in Linux in this change, in 2003: https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/?id=45c1a159b85b3b30afd26a77b4be312226bba416 PTRACE_O_TRACESYSGOOD was supported at least as of this change, in 2002: https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/?id=acc7088569c8eef04eeed0eff51d23bb5bcff964 PTRACE_O_TRACEFORK, PTRACE_O_TRACEVFORK, PTRACE_O_TRACEEXEC and PTRACE_O_TRACECLONE were introduced in this change, in 2002: https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/?id=a0691b116f6a4473f0fa264210ab9b95771a2b46 Change-Id: Iffb906549a89cc6b619427f976ec044706ab1e8d
Diffstat (limited to 'gdb/nat')
-rw-r--r--gdb/nat/linux-ptrace.c186
-rw-r--r--gdb/nat/linux-ptrace.h5
2 files changed, 9 insertions, 182 deletions
diff --git a/gdb/nat/linux-ptrace.c b/gdb/nat/linux-ptrace.c
index 7258f4a..5b3086e 100644
--- a/gdb/nat/linux-ptrace.c
+++ b/gdb/nat/linux-ptrace.c
@@ -301,20 +301,6 @@ linux_fork_to_function (gdb_byte *child_stack, int (*function) (void *))
}
/* A helper function for linux_check_ptrace_features, called after
- the child forks a grandchild. */
-
-static int
-linux_grandchild_function (void *child_stack)
-{
- /* Free any allocated stack. */
- xfree (child_stack);
-
- /* This code is only reacheable by the grandchild (child's child)
- process. */
- _exit (0);
-}
-
-/* A helper function for linux_check_ptrace_features, called after
the parent process forks a child. The child allows itself to
be traced by its parent. */
@@ -324,16 +310,11 @@ linux_child_function (void *child_stack)
ptrace (PTRACE_TRACEME, 0, (PTRACE_TYPE_ARG3) 0, (PTRACE_TYPE_ARG4) 0);
kill (getpid (), SIGSTOP);
- /* Fork a grandchild. */
- linux_fork_to_function ((gdb_byte *) child_stack, linux_grandchild_function);
-
/* This code is only reacheable by the child (grandchild's parent)
process. */
_exit (0);
}
-static void linux_test_for_tracesysgood (int child_pid);
-static void linux_test_for_tracefork (int child_pid);
static void linux_test_for_exitkill (int child_pid);
/* Determine ptrace features available on this target. */
@@ -343,8 +324,15 @@ linux_check_ptrace_features (void)
{
int child_pid, ret, status;
- /* Initialize the options. */
- supported_ptrace_options = 0;
+ /* Initialize the options. We consider that these options are always
+ supported. */
+ supported_ptrace_options
+ = (PTRACE_O_TRACESYSGOOD
+ | PTRACE_O_TRACECLONE
+ | PTRACE_O_TRACEFORK
+ | PTRACE_O_TRACEVFORK
+ | PTRACE_O_TRACEVFORKDONE
+ | PTRACE_O_TRACEEXEC);
/* Fork a child so we can do some testing. The child will call
linux_child_function and will get traced. The child will
@@ -362,104 +350,12 @@ linux_check_ptrace_features (void)
error (_("linux_check_ptrace_features: waitpid: unexpected status %d."),
status);
- linux_test_for_tracesysgood (child_pid);
-
- linux_test_for_tracefork (child_pid);
-
linux_test_for_exitkill (child_pid);
/* Kill child_pid. */
kill_child (child_pid, "linux_check_ptrace_features");
}
-/* Determine if PTRACE_O_TRACESYSGOOD can be used to catch
- syscalls. */
-
-static void
-linux_test_for_tracesysgood (int child_pid)
-{
- int ret;
-
- ret = ptrace (PTRACE_SETOPTIONS, child_pid, (PTRACE_TYPE_ARG3) 0,
- (PTRACE_TYPE_ARG4) PTRACE_O_TRACESYSGOOD);
-
- if (ret == 0)
- supported_ptrace_options |= PTRACE_O_TRACESYSGOOD;
-}
-
-/* Determine if PTRACE_O_TRACEFORK can be used to follow fork
- events. */
-
-static void
-linux_test_for_tracefork (int child_pid)
-{
- int ret, status;
- long second_pid;
-
- /* First, set the PTRACE_O_TRACEFORK option. If this fails, we
- know for sure that it is not supported. */
- ret = ptrace (PTRACE_SETOPTIONS, child_pid, (PTRACE_TYPE_ARG3) 0,
- (PTRACE_TYPE_ARG4) PTRACE_O_TRACEFORK);
-
- if (ret != 0)
- return;
-
- /* Check if the target supports PTRACE_O_TRACEVFORKDONE. */
- ret = ptrace (PTRACE_SETOPTIONS, child_pid, (PTRACE_TYPE_ARG3) 0,
- (PTRACE_TYPE_ARG4) (PTRACE_O_TRACEFORK
- | PTRACE_O_TRACEVFORKDONE));
- if (ret == 0)
- supported_ptrace_options |= PTRACE_O_TRACEVFORKDONE;
-
- /* Setting PTRACE_O_TRACEFORK did not cause an error, however we
- don't know for sure that the feature is available; old
- versions of PTRACE_SETOPTIONS ignored unknown options.
- Therefore, we attach to the child process, use PTRACE_SETOPTIONS
- to enable fork tracing, and let it fork. If the process exits,
- we assume that we can't use PTRACE_O_TRACEFORK; if we get the
- fork notification, and we can extract the new child's PID, then
- we assume that we can.
-
- We do not explicitly check for vfork tracing here. It is
- assumed that vfork tracing is available whenever fork tracing
- is available. */
- ret = ptrace (PTRACE_CONT, child_pid, (PTRACE_TYPE_ARG3) 0,
- (PTRACE_TYPE_ARG4) 0);
- if (ret != 0)
- warning (_("linux_test_for_tracefork: failed to resume child"));
-
- ret = my_waitpid (child_pid, &status, 0);
-
- /* Check if we received a fork event notification. */
- if (ret == child_pid && WIFSTOPPED (status)
- && linux_ptrace_get_extended_event (status) == PTRACE_EVENT_FORK)
- {
- /* We did receive a fork event notification. Make sure its PID
- is reported. */
- second_pid = 0;
- ret = ptrace (PTRACE_GETEVENTMSG, child_pid, (PTRACE_TYPE_ARG3) 0,
- (PTRACE_TYPE_ARG4) &second_pid);
- if (ret == 0 && second_pid != 0)
- {
- int second_status;
-
- /* We got the PID from the grandchild, which means fork
- tracing is supported. */
- supported_ptrace_options |= PTRACE_O_TRACECLONE;
- supported_ptrace_options |= (PTRACE_O_TRACEFORK
- | PTRACE_O_TRACEVFORK
- | PTRACE_O_TRACEEXEC);
-
- /* Do some cleanup and kill the grandchild. */
- my_waitpid (second_pid, &second_status, 0);
- kill_child (second_pid, "linux_test_for_tracefork");
- }
- }
- else
- warning (_("linux_test_for_tracefork: unexpected result from waitpid "
- "(%d, status 0x%x)"), ret, status);
-}
-
/* Determine if PTRACE_O_EXITKILL can be used. */
static void
@@ -507,70 +403,6 @@ linux_disable_event_reporting (pid_t pid)
ptrace (PTRACE_SETOPTIONS, pid, (PTRACE_TYPE_ARG3) 0, 0);
}
-/* Returns non-zero if PTRACE_OPTIONS is contained within
- SUPPORTED_PTRACE_OPTIONS, therefore supported. Returns 0
- otherwise. */
-
-static int
-ptrace_supports_feature (int ptrace_options)
-{
- if (supported_ptrace_options == -1)
- linux_check_ptrace_features ();
-
- return ((supported_ptrace_options & ptrace_options) == ptrace_options);
-}
-
-/* Returns non-zero if PTRACE_EVENT_FORK is supported by ptrace,
- 0 otherwise. Note that if PTRACE_EVENT_FORK is supported so is
- PTRACE_EVENT_CLONE, PTRACE_EVENT_EXEC and PTRACE_EVENT_VFORK,
- since they were all added to the kernel at the same time. */
-
-int
-linux_supports_tracefork (void)
-{
- return ptrace_supports_feature (PTRACE_O_TRACEFORK);
-}
-
-/* Returns non-zero if PTRACE_EVENT_EXEC is supported by ptrace,
- 0 otherwise. Note that if PTRACE_EVENT_FORK is supported so is
- PTRACE_EVENT_CLONE, PTRACE_EVENT_FORK and PTRACE_EVENT_VFORK,
- since they were all added to the kernel at the same time. */
-
-int
-linux_supports_traceexec (void)
-{
- return ptrace_supports_feature (PTRACE_O_TRACEEXEC);
-}
-
-/* Returns non-zero if PTRACE_EVENT_CLONE is supported by ptrace,
- 0 otherwise. Note that if PTRACE_EVENT_CLONE is supported so is
- PTRACE_EVENT_FORK, PTRACE_EVENT_EXEC and PTRACE_EVENT_VFORK,
- since they were all added to the kernel at the same time. */
-
-int
-linux_supports_traceclone (void)
-{
- return ptrace_supports_feature (PTRACE_O_TRACECLONE);
-}
-
-/* Returns non-zero if PTRACE_O_TRACEVFORKDONE is supported by
- ptrace, 0 otherwise. */
-
-int
-linux_supports_tracevforkdone (void)
-{
- return ptrace_supports_feature (PTRACE_O_TRACEVFORKDONE);
-}
-
-/* Returns non-zero if PTRACE_O_TRACESYSGOOD is supported by ptrace,
- 0 otherwise. */
-
-int
-linux_supports_tracesysgood (void)
-{
- return ptrace_supports_feature (PTRACE_O_TRACESYSGOOD);
-}
-
/* Display possible problems on this system. Display them only once per GDB
execution. */
diff --git a/gdb/nat/linux-ptrace.h b/gdb/nat/linux-ptrace.h
index 2ac59a7..4694046 100644
--- a/gdb/nat/linux-ptrace.h
+++ b/gdb/nat/linux-ptrace.h
@@ -187,11 +187,6 @@ extern void linux_ptrace_init_warnings (void);
extern void linux_check_ptrace_features (void);
extern void linux_enable_event_reporting (pid_t pid, int attached);
extern void linux_disable_event_reporting (pid_t pid);
-extern int linux_supports_tracefork (void);
-extern int linux_supports_traceexec (void);
-extern int linux_supports_traceclone (void);
-extern int linux_supports_tracevforkdone (void);
-extern int linux_supports_tracesysgood (void);
extern int linux_ptrace_get_extended_event (int wstat);
extern int linux_is_extended_waitstatus (int wstat);
extern int linux_wstatus_maybe_breakpoint (int wstat);