From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24234 invoked by alias); 27 Feb 2012 16:24:41 -0000 Received: (qmail 24224 invoked by uid 22791); 27 Feb 2012 16:24:39 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 27 Feb 2012 16:24:23 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q1RGOJx3025103 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 27 Feb 2012 11:24:19 -0500 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q1RGOIN0026943; Mon, 27 Feb 2012 11:24:19 -0500 Message-ID: <4F4BAE32.8050402@redhat.com> Date: Mon, 27 Feb 2012 16:31:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120216 Thunderbird/10.0.1 MIME-Version: 1.0 To: Yao Qi CC: gdb-patches@sourceware.org Subject: move pid_is_stopped to common/ References: <20120224222127.14659.51317.stgit@hit-nxdomain.opendns.com> <4F487823.5030006@codesourcery.com> In-Reply-To: <4F487823.5030006@codesourcery.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-02/txt/msg00630.txt.bz2 On 02/25/2012 05:56 AM, Yao Qi wrote: > This function is exactly the same as linux-nat.c:pid_is_stopped, so > why don't we move them to common/linux-linuxprocfs.c? I've applied this as follow up. Thanks, -- Pedro Alves 2012-02-27 Pedro Alves gdb/gdbserver/ * linux-low.c (pid_is_stopped): Delete, moved to common/. (linux_attach_lwp_1): Adjust to use linux_proc_pid_is_stopped. gdb/ * linux-nat.c (pid_is_stopped): Delete, moved to common/. (linux_nat_post_attach_wait): Adjust to use linux_proc_pid_is_stopped. * common/linux-procfs.h (linux_proc_pid_is_stopped): Declare. * common/linux-procfs.c (linux_proc_pid_is_stopped): New function, based on pid_is_stopped from both linux-nat.c and gdbserver/linux-low.c, and renamed. --- gdb/common/linux-procfs.c | 31 +++++++++++++++++++++++++++++++ gdb/common/linux-procfs.h | 5 +++++ gdb/gdbserver/linux-low.c | 33 +-------------------------------- gdb/linux-nat.c | 33 +-------------------------------- 4 files changed, 38 insertions(+), 64 deletions(-) diff --git a/gdb/common/linux-procfs.c b/gdb/common/linux-procfs.c index 421f36e..165383e 100644 --- a/gdb/common/linux-procfs.c +++ b/gdb/common/linux-procfs.c @@ -53,3 +53,34 @@ linux_proc_get_tgid (int lwpid) return tgid; } + +/* Detect `T (stopped)' in `/proc/PID/status'. + Other states including `T (tracing stop)' are reported as false. */ + +int +linux_proc_pid_is_stopped (pid_t pid) +{ + FILE *status_file; + char buf[100]; + int retval = 0; + + snprintf (buf, sizeof (buf), "/proc/%d/status", (int) pid); + status_file = fopen (buf, "r"); + if (status_file != NULL) + { + int have_state = 0; + + while (fgets (buf, sizeof (buf), status_file)) + { + if (strncmp (buf, "State:", 6) == 0) + { + have_state = 1; + break; + } + } + if (have_state && strstr (buf, "T (stopped)") != NULL) + retval = 1; + fclose (status_file); + } + return retval; +} diff --git a/gdb/common/linux-procfs.h b/gdb/common/linux-procfs.h index a4ba4a1..c1e5547 100644 --- a/gdb/common/linux-procfs.h +++ b/gdb/common/linux-procfs.h @@ -26,4 +26,9 @@ extern int linux_proc_get_tgid (int lwpid); +/* Detect `T (stopped)' in `/proc/PID/status'. + Other states including `T (tracing stop)' are reported as false. */ + +extern int linux_proc_pid_is_stopped (pid_t pid); + #endif /* COMMON_LINUX_PROCFS_H */ diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index f2887e6..8f57ee3 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -598,37 +598,6 @@ linux_create_inferior (char *program, char **allargs) return pid; } -/* Detect `T (stopped)' in `/proc/PID/status'. - Other states including `T (tracing stop)' are reported as false. */ - -static int -pid_is_stopped (pid_t pid) -{ - FILE *status_file; - char buf[100]; - int retval = 0; - - snprintf (buf, sizeof (buf), "/proc/%d/status", (int) pid); - status_file = fopen (buf, "r"); - if (status_file != NULL) - { - int have_state = 0; - - while (fgets (buf, sizeof (buf), status_file)) - { - if (strncmp (buf, "State:", 6) == 0) - { - have_state = 1; - break; - } - } - if (have_state && strstr (buf, "T (stopped)") != NULL) - retval = 1; - fclose (status_file); - } - return retval; -} - /* Attach to an inferior process. */ static void @@ -674,7 +643,7 @@ linux_attach_lwp_1 (unsigned long lwpid, int initial) ptrace call on this LWP. */ new_lwp->must_set_ptrace_flags = 1; - if (pid_is_stopped (lwpid)) + if (linux_proc_pid_is_stopped (lwpid)) { if (debug_threads) fprintf (stderr, diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 3731096..e426387 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -1356,37 +1356,6 @@ exit_lwp (struct lwp_info *lp) delete_lwp (lp->ptid); } -/* Detect `T (stopped)' in `/proc/PID/status'. - Other states including `T (tracing stop)' are reported as false. */ - -static int -pid_is_stopped (pid_t pid) -{ - FILE *status_file; - char buf[100]; - int retval = 0; - - snprintf (buf, sizeof (buf), "/proc/%d/status", (int) pid); - status_file = fopen (buf, "r"); - if (status_file != NULL) - { - int have_state = 0; - - while (fgets (buf, sizeof (buf), status_file)) - { - if (strncmp (buf, "State:", 6) == 0) - { - have_state = 1; - break; - } - } - if (have_state && strstr (buf, "T (stopped)") != NULL) - retval = 1; - fclose (status_file); - } - return retval; -} - /* Wait for the LWP specified by LP, which we have just attached to. Returns a wait status for that LWP, to cache. */ @@ -1397,7 +1366,7 @@ linux_nat_post_attach_wait (ptid_t ptid, int first, int *cloned, pid_t new_pid, pid = GET_LWP (ptid); int status; - if (pid_is_stopped (pid)) + if (linux_proc_pid_is_stopped (pid)) { if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog,