This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
small optimization of linux_lwp_is_zombie
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Tue, 11 Oct 2011 15:01:59 +0100
- Subject: small optimization of linux_lwp_is_zombie
I noticed this function goes on reading the rest of the
file after the "State:" line when the lwp is not zombie.
Tested on x86_64-linux and applied.
--
Pedro Alves
2011-10-11 Pedro Alves <pedro@codesourcery.com>
gdb/
* linux-nat.c (linux_lwp_is_zombie): Return early if the LWP is
not zombie instead of reading the whole file.
---
gdb/linux-nat.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
Index: src/gdb/linux-nat.c
===================================================================
--- src.orig/gdb/linux-nat.c 2011-10-11 14:53:21.678607147 +0100
+++ src/gdb/linux-nat.c 2011-10-11 14:54:28.018607135 +0100
@@ -2382,7 +2382,8 @@ linux_lwp_is_zombie (long lwp)
{
char buffer[MAXPATHLEN];
FILE *procfile;
- int retval = 0;
+ int retval;
+ int have_state;
xsnprintf (buffer, sizeof (buffer), "/proc/%ld/status", lwp);
procfile = fopen (buffer, "r");
@@ -2391,14 +2392,17 @@ linux_lwp_is_zombie (long lwp)
warning (_("unable to open /proc file '%s'"), buffer);
return 0;
}
+
+ have_state = 0;
while (fgets (buffer, sizeof (buffer), procfile) != NULL)
- if (strcmp (buffer, "State:\tZ (zombie)\n") == 0)
+ if (strncmp (buffer, "State:", 6) == 0)
{
- retval = 1;
+ have_state = 1;
break;
}
+ retval = (have_state
+ && strcmp (buffer, "State:\tZ (zombie)\n") == 0);
fclose (procfile);
-
return retval;
}