From 5f572decf9c6fe42f07706514b5056e7fc65cfef Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Tue, 13 Mar 2012 15:00:37 +0000 Subject: [PATCH] gdb/ * Makefile.in (linux-ptrace.o): New. * common/linux-procfs.c (linux_proc_pid_is_zombie): New, from linux-nat.c. * common/linux-procfs.h (linux_proc_pid_is_zombie): New declaration. * common/linux-ptrace.c: New file. * config/alpha/alpha-linux.mh (NATDEPFILES): Add linux-ptrace.o. * config/arm/linux.mh: Likewise. * config/i386/linux.mh: Likewise. * config/i386/linux64.mh: Likewise. * config/ia64/linux.mh: Likewise. * config/m32r/linux.mh: Likewise. * config/m68k/linux.mh: Likewise. * config/mips/linux.mh: Likewise. * config/pa/linux.mh: Likewise. * config/powerpc/linux.mh: Likewise. * config/powerpc/ppc64-linux.mh: Likewise. * config/powerpc/spu-linux.mh: Likewise. * config/s390/s390.mh: Likewise. * config/sparc/linux.mh: Likewise. * config/sparc/linux64.mh: Likewise. * config/xtensa/linux.mh: Likewise. * linux-nat.c (linux_lwp_is_zombie): Remove, move it to common/linux-procfs.c. (wait_lwp): Rename linux_lwp_is_zombie to linux_proc_pid_is_zombie. gdb/gdbserver/ * Makefile.in (linux-ptrace.o): New. * configure.srv (arm*-*-linux*, bfin-*-*linux*, crisv32-*-linux*) (cris-*-linux*, i[34567]86-*-linux*, ia64-*-linux*, m32r*-*-linux*) (m68*-*-linux*, m68*-*-uclinux*, mips*-*-linux*, powerpc*-*-linux*) (s390*-*-linux*, sh*-*-linux*, sparc*-*-linux*, tic6x-*-uclinux) (x86_64-*-linux*, xtensa*-*-linux*): Add linux-ptrace.o to SRV_TGTOBJ of these targets. * linux-low.c (linux_attach_lwp_1): Remove redundent else clause. --- gdb/ChangeLog | 27 ++++++++++++++++++++++ gdb/Makefile.in | 4 ++++ gdb/common/linux-procfs.c | 31 ++++++++++++++++++++++++++ gdb/common/linux-procfs.h | 4 ++++ gdb/common/linux-ptrace.c | 26 ++++++++++++++++++++++ gdb/config/alpha/alpha-linux.mh | 2 +- gdb/config/arm/linux.mh | 2 +- gdb/config/i386/linux.mh | 2 +- gdb/config/i386/linux64.mh | 2 +- gdb/config/ia64/linux.mh | 2 +- gdb/config/m32r/linux.mh | 2 +- gdb/config/m68k/linux.mh | 2 +- gdb/config/mips/linux.mh | 2 +- gdb/config/pa/linux.mh | 2 +- gdb/config/powerpc/linux.mh | 2 +- gdb/config/powerpc/ppc64-linux.mh | 2 +- gdb/config/powerpc/spu-linux.mh | 2 +- gdb/config/s390/s390.mh | 2 +- gdb/config/sparc/linux.mh | 2 +- gdb/config/sparc/linux64.mh | 2 +- gdb/config/xtensa/linux.mh | 2 +- gdb/gdbserver/ChangeLog | 11 +++++++++ gdb/gdbserver/Makefile.in | 3 +++ gdb/gdbserver/configure.srv | 17 ++++++++++++++ gdb/gdbserver/linux-low.c | 8 +++---- gdb/linux-nat.c | 37 +++---------------------------- 26 files changed, 146 insertions(+), 54 deletions(-) create mode 100644 gdb/common/linux-ptrace.c diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c422451c7e8..f7f564c6dab 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,30 @@ +2012-03-13 Jan Kratochvil + + * Makefile.in (linux-ptrace.o): New. + * common/linux-procfs.c (linux_proc_pid_is_zombie): New, + from linux-nat.c. + * common/linux-procfs.h (linux_proc_pid_is_zombie): New declaration. + * common/linux-ptrace.c: New file. + * config/alpha/alpha-linux.mh (NATDEPFILES): Add linux-ptrace.o. + * config/arm/linux.mh: Likewise. + * config/i386/linux.mh: Likewise. + * config/i386/linux64.mh: Likewise. + * config/ia64/linux.mh: Likewise. + * config/m32r/linux.mh: Likewise. + * config/m68k/linux.mh: Likewise. + * config/mips/linux.mh: Likewise. + * config/pa/linux.mh: Likewise. + * config/powerpc/linux.mh: Likewise. + * config/powerpc/ppc64-linux.mh: Likewise. + * config/powerpc/spu-linux.mh: Likewise. + * config/s390/s390.mh: Likewise. + * config/sparc/linux.mh: Likewise. + * config/sparc/linux64.mh: Likewise. + * config/xtensa/linux.mh: Likewise. + * linux-nat.c (linux_lwp_is_zombie): Remove, move it to + common/linux-procfs.c. + (wait_lwp): Rename linux_lwp_is_zombie to linux_proc_pid_is_zombie. + 2012-03-13 Hui Zhu Pedro Alves diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 84eda7da02a..4d856624552 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1929,6 +1929,10 @@ linux-procfs.o: $(srcdir)/common/linux-procfs.c $(COMPILE) $(srcdir)/common/linux-procfs.c $(POSTCOMPILE) +linux-ptrace.o: $(srcdir)/common/linux-ptrace.c + $(COMPILE) $(srcdir)/common/linux-ptrace.c + $(POSTCOMPILE) + common-agent.o: $(srcdir)/common/agent.c $(COMPILE) $(srcdir)/common/agent.c $(POSTCOMPILE) diff --git a/gdb/common/linux-procfs.c b/gdb/common/linux-procfs.c index 165383e8755..b7d98a53983 100644 --- a/gdb/common/linux-procfs.c +++ b/gdb/common/linux-procfs.c @@ -84,3 +84,34 @@ linux_proc_pid_is_stopped (pid_t pid) } return retval; } + +/* See linux-procfs.h declaration. */ + +int +linux_proc_pid_is_zombie (pid_t pid) +{ + char buffer[100]; + FILE *procfile; + int retval; + int have_state; + + xsnprintf (buffer, sizeof (buffer), "/proc/%d/status", (int) pid); + procfile = fopen (buffer, "r"); + if (procfile == NULL) + { + warning (_("unable to open /proc file '%s'"), buffer); + return 0; + } + + have_state = 0; + while (fgets (buffer, sizeof (buffer), procfile) != NULL) + if (strncmp (buffer, "State:", 6) == 0) + { + have_state = 1; + break; + } + retval = (have_state + && strcmp (buffer, "State:\tZ (zombie)\n") == 0); + fclose (procfile); + return retval; +} diff --git a/gdb/common/linux-procfs.h b/gdb/common/linux-procfs.h index c1e55474ad7..130adeb14a7 100644 --- a/gdb/common/linux-procfs.h +++ b/gdb/common/linux-procfs.h @@ -31,4 +31,8 @@ extern int linux_proc_get_tgid (int lwpid); extern int linux_proc_pid_is_stopped (pid_t pid); +/* Return non-zero if PID is a zombie. */ + +extern int linux_proc_pid_is_zombie (pid_t pid); + #endif /* COMMON_LINUX_PROCFS_H */ diff --git a/gdb/common/linux-ptrace.c b/gdb/common/linux-ptrace.c new file mode 100644 index 00000000000..6dea677306d --- /dev/null +++ b/gdb/common/linux-ptrace.c @@ -0,0 +1,26 @@ +/* Linux-specific ptrace manipulation routines. + Copyright (C) 2012 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 . */ + +#ifdef GDBSERVER +#include "server.h" +#else +#include "defs.h" +#include "gdb_string.h" +#endif + +#include "linux-ptrace.h" diff --git a/gdb/config/alpha/alpha-linux.mh b/gdb/config/alpha/alpha-linux.mh index 15dc9894a39..9eb9e4b7291 100644 --- a/gdb/config/alpha/alpha-linux.mh +++ b/gdb/config/alpha/alpha-linux.mh @@ -2,7 +2,7 @@ NAT_FILE= config/nm-linux.h NATDEPFILES= inf-ptrace.o alpha-linux-nat.o \ fork-child.o proc-service.o linux-thread-db.o \ - linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o + linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o NAT_CDEPS = $(srcdir)/proc-service.list # The dynamically loaded libthread_db needs access to symbols in the diff --git a/gdb/config/arm/linux.mh b/gdb/config/arm/linux.mh index 78918d26606..c0a1c66804a 100644 --- a/gdb/config/arm/linux.mh +++ b/gdb/config/arm/linux.mh @@ -3,7 +3,7 @@ NAT_FILE= config/nm-linux.h NATDEPFILES= inf-ptrace.o fork-child.o arm-linux-nat.o \ proc-service.o linux-thread-db.o \ - linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o + linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o NAT_CDEPS = $(srcdir)/proc-service.list LOADLIBES= -ldl $(RDYNAMIC) diff --git a/gdb/config/i386/linux.mh b/gdb/config/i386/linux.mh index 3a158c65977..8316d870eac 100644 --- a/gdb/config/i386/linux.mh +++ b/gdb/config/i386/linux.mh @@ -4,7 +4,7 @@ NAT_FILE= config/nm-linux.h NATDEPFILES= inf-ptrace.o fork-child.o \ i386-nat.o i386-linux-nat.o \ proc-service.o linux-thread-db.o \ - linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o + linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o NAT_CDEPS = $(srcdir)/proc-service.list # The dynamically loaded libthread_db needs access to symbols in the diff --git a/gdb/config/i386/linux64.mh b/gdb/config/i386/linux64.mh index a5e8c14b3a6..d2b95fd605c 100644 --- a/gdb/config/i386/linux64.mh +++ b/gdb/config/i386/linux64.mh @@ -3,7 +3,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \ i386-nat.o amd64-nat.o amd64-linux-nat.o \ linux-nat.o linux-osdata.o \ proc-service.o linux-thread-db.o linux-fork.o \ - linux-procfs.o + linux-procfs.o linux-ptrace.o NAT_FILE= config/nm-linux.h NAT_CDEPS = $(srcdir)/proc-service.list diff --git a/gdb/config/ia64/linux.mh b/gdb/config/ia64/linux.mh index c72929c6f36..1a4c68e0937 100644 --- a/gdb/config/ia64/linux.mh +++ b/gdb/config/ia64/linux.mh @@ -5,7 +5,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \ core-regset.o ia64-linux-nat.o \ proc-service.o linux-thread-db.o \ linux-nat.o linux-osdata.o linux-fork.o \ - linux-procfs.o + linux-procfs.o linux-ptrace.o NAT_CDEPS = $(srcdir)/proc-service.list LOADLIBES = -ldl $(RDYNAMIC) diff --git a/gdb/config/m32r/linux.mh b/gdb/config/m32r/linux.mh index 32a442848a8..b4618064bff 100644 --- a/gdb/config/m32r/linux.mh +++ b/gdb/config/m32r/linux.mh @@ -3,7 +3,7 @@ NAT_FILE= config/nm-linux.h NATDEPFILES= inf-ptrace.o fork-child.o \ m32r-linux-nat.o proc-service.o linux-thread-db.o \ - linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o + linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o NAT_CDEPS = $(srcdir)/proc-service.list LOADLIBES= -ldl $(RDYNAMIC) diff --git a/gdb/config/m68k/linux.mh b/gdb/config/m68k/linux.mh index b116819c863..e3aaf382c8c 100644 --- a/gdb/config/m68k/linux.mh +++ b/gdb/config/m68k/linux.mh @@ -4,7 +4,7 @@ NAT_FILE= config/nm-linux.h NATDEPFILES= inf-ptrace.o fork-child.o \ m68klinux-nat.o \ proc-service.o linux-thread-db.o \ - linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o + linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o NAT_CDEPS = $(srcdir)/proc-service.list # The dynamically loaded libthread_db needs access to symbols in the diff --git a/gdb/config/mips/linux.mh b/gdb/config/mips/linux.mh index 1ef3bce5659..2f8e5dd3094 100644 --- a/gdb/config/mips/linux.mh +++ b/gdb/config/mips/linux.mh @@ -3,7 +3,7 @@ NAT_FILE= config/nm-linux.h NATDEPFILES= inf-ptrace.o fork-child.o mips-linux-nat.o \ linux-thread-db.o proc-service.o \ linux-nat.o linux-osdata.o linux-fork.o \ - linux-procfs.o + linux-procfs.o linux-ptrace.o NAT_CDEPS = $(srcdir)/proc-service.list LOADLIBES = -ldl $(RDYNAMIC) diff --git a/gdb/config/pa/linux.mh b/gdb/config/pa/linux.mh index e9b7114117e..fa46db6ebe5 100644 --- a/gdb/config/pa/linux.mh +++ b/gdb/config/pa/linux.mh @@ -3,7 +3,7 @@ NAT_FILE= config/nm-linux.h NATDEPFILES= inf-ptrace.o fork-child.o \ hppa-linux-nat.o proc-service.o linux-thread-db.o \ linux-nat.o linux-osdata.o linux-fork.o \ - linux-procfs.o + linux-procfs.o linux-ptrace.o NAT_CDEPS = $(srcdir)/proc-service.list LOADLIBES = -ldl $(RDYNAMIC) diff --git a/gdb/config/powerpc/linux.mh b/gdb/config/powerpc/linux.mh index 0ae93681f4a..b0d4ce7c55c 100644 --- a/gdb/config/powerpc/linux.mh +++ b/gdb/config/powerpc/linux.mh @@ -5,7 +5,7 @@ XM_CLIBS= NAT_FILE= config/nm-linux.h NATDEPFILES= inf-ptrace.o fork-child.o \ ppc-linux-nat.o proc-service.o linux-thread-db.o \ - linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o + linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o NAT_CDEPS = $(srcdir)/proc-service.list LOADLIBES = -ldl $(RDYNAMIC) diff --git a/gdb/config/powerpc/ppc64-linux.mh b/gdb/config/powerpc/ppc64-linux.mh index bf1bb5bde08..367a81853b5 100644 --- a/gdb/config/powerpc/ppc64-linux.mh +++ b/gdb/config/powerpc/ppc64-linux.mh @@ -5,7 +5,7 @@ XM_CLIBS= NAT_FILE= config/nm-linux.h NATDEPFILES= inf-ptrace.o fork-child.o \ ppc-linux-nat.o proc-service.o linux-thread-db.o \ - linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o + linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o NAT_CDEPS = $(srcdir)/proc-service.list # The PowerPC has severe limitations on TOC size, and uses them even diff --git a/gdb/config/powerpc/spu-linux.mh b/gdb/config/powerpc/spu-linux.mh index f6e7396881e..1bc279a8138 100644 --- a/gdb/config/powerpc/spu-linux.mh +++ b/gdb/config/powerpc/spu-linux.mh @@ -4,5 +4,5 @@ # PPU side of the Cell BE and debugging the SPU side. NATDEPFILES = spu-linux-nat.o fork-child.o inf-ptrace.o \ - linux-procfs.o + linux-procfs.o linux-ptrace.o diff --git a/gdb/config/s390/s390.mh b/gdb/config/s390/s390.mh index 44c7a9a6c3b..a53835c4fa5 100644 --- a/gdb/config/s390/s390.mh +++ b/gdb/config/s390/s390.mh @@ -2,6 +2,6 @@ NAT_FILE= config/nm-linux.h NATDEPFILES= inf-ptrace.o fork-child.o s390-nat.o \ linux-thread-db.o proc-service.o \ - linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o + linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o NAT_CDEPS = $(srcdir)/proc-service.list LOADLIBES = -ldl $(RDYNAMIC) diff --git a/gdb/config/sparc/linux.mh b/gdb/config/sparc/linux.mh index 25c4ad5b94e..6a2cefd7b5c 100644 --- a/gdb/config/sparc/linux.mh +++ b/gdb/config/sparc/linux.mh @@ -4,7 +4,7 @@ NATDEPFILES= sparc-nat.o sparc-linux-nat.o \ core-regset.o fork-child.o inf-ptrace.o \ proc-service.o linux-thread-db.o \ linux-nat.o linux-osdata.o linux-fork.o \ - linux-procfs.o + linux-procfs.o linux-ptrace.o NAT_CDEPS = $(srcdir)/proc-service.list # The dynamically loaded libthread_db needs access to symbols in the diff --git a/gdb/config/sparc/linux64.mh b/gdb/config/sparc/linux64.mh index 363e19b9956..d1e1a97162f 100644 --- a/gdb/config/sparc/linux64.mh +++ b/gdb/config/sparc/linux64.mh @@ -5,7 +5,7 @@ NATDEPFILES= sparc-nat.o sparc64-nat.o sparc64-linux-nat.o \ fork-child.o inf-ptrace.o \ proc-service.o linux-thread-db.o \ linux-nat.o linux-osdata.o linux-fork.o \ - linux-procfs.o + linux-procfs.o linux-ptrace.o NAT_CDEPS = $(srcdir)/proc-service.list # The dynamically loaded libthread_db needs access to symbols in the diff --git a/gdb/config/xtensa/linux.mh b/gdb/config/xtensa/linux.mh index c637ec757f6..deffe25ed42 100644 --- a/gdb/config/xtensa/linux.mh +++ b/gdb/config/xtensa/linux.mh @@ -4,7 +4,7 @@ NAT_FILE= config/nm-linux.h NATDEPFILES= inf-ptrace.o fork-child.o xtensa-linux-nat.o \ linux-thread-db.o proc-service.o \ - linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o + linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o NAT_CDEPS = $(srcdir)/proc-service.list LOADLIBES = -ldl $(RDYNAMIC) diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 04c0709b2fe..726a6b43871 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,14 @@ +2012-03-13 Jan Kratochvil + + * Makefile.in (linux-ptrace.o): New. + * configure.srv (arm*-*-linux*, bfin-*-*linux*, crisv32-*-linux*) + (cris-*-linux*, i[34567]86-*-linux*, ia64-*-linux*, m32r*-*-linux*) + (m68*-*-linux*, m68*-*-uclinux*, mips*-*-linux*, powerpc*-*-linux*) + (s390*-*-linux*, sh*-*-linux*, sparc*-*-linux*, tic6x-*-uclinux) + (x86_64-*-linux*, xtensa*-*-linux*): Add linux-ptrace.o to SRV_TGTOBJ + of these targets. + * linux-low.c (linux_attach_lwp_1): Remove redundent else clause. + 2012-03-08 Yao Qi Pedro Alves diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in index ce220cbc099..6d77ce2fed2 100644 --- a/gdb/gdbserver/Makefile.in +++ b/gdb/gdbserver/Makefile.in @@ -415,6 +415,9 @@ signals.o: ../common/signals.c $(server_h) $(signals_def) linux-procfs.o: ../common/linux-procfs.c $(server_h) $(CC) -c $(CPPFLAGS) $(INTERNAL_CFLAGS) $< -DGDBSERVER +linux-ptrace.o: ../common/linux-ptrace.c $(server_h) + $(CC) -c $(CPPFLAGS) $(INTERNAL_CFLAGS) $< -DGDBSERVER + common-utils.o: ../common/common-utils.c $(server_h) $(CC) -c $(CPPFLAGS) $(INTERNAL_CFLAGS) $< -DGDBSERVER diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv index 3358c3377d5..bdd99167b34 100644 --- a/gdb/gdbserver/configure.srv +++ b/gdb/gdbserver/configure.srv @@ -47,6 +47,7 @@ case "${target}" in srv_regobj="${srv_regobj} arm-with-vfpv3.o" srv_regobj="${srv_regobj} arm-with-neon.o" srv_tgtobj="linux-low.o linux-osdata.o linux-arm-low.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_xmlfiles="arm-with-iwmmxt.xml" srv_xmlfiles="${srv_xmlfiles} arm-with-vfpv2.xml" srv_xmlfiles="${srv_xmlfiles} arm-with-vfpv3.xml" @@ -69,16 +70,19 @@ case "${target}" in ;; bfin-*-*linux*) srv_regobj=reg-bfin.o srv_tgtobj="linux-low.o linux-osdata.o linux-bfin-low.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_linux_usrregs=yes srv_linux_thread_db=yes ;; crisv32-*-linux*) srv_regobj=reg-crisv32.o srv_tgtobj="linux-low.o linux-osdata.o linux-crisv32-low.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_linux_regsets=yes srv_linux_thread_db=yes ;; cris-*-linux*) srv_regobj=reg-cris.o srv_tgtobj="linux-low.o linux-osdata.o linux-cris-low.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_linux_usrregs=yes srv_linux_thread_db=yes ;; @@ -93,6 +97,7 @@ case "${target}" in srv_xmlfiles="${srv_xmlfiles} $srv_amd64_linux_xmlfiles" fi srv_tgtobj="linux-low.o linux-osdata.o linux-x86-low.o i386-low.o i387-fp.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_linux_usrregs=yes srv_linux_regsets=yes srv_linux_thread_db=yes @@ -124,10 +129,12 @@ case "${target}" in ;; ia64-*-linux*) srv_regobj=reg-ia64.o srv_tgtobj="linux-low.o linux-osdata.o linux-ia64-low.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_linux_usrregs=yes ;; m32r*-*-linux*) srv_regobj=reg-m32r.o srv_tgtobj="linux-low.o linux-osdata.o linux-m32r-low.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_linux_usrregs=yes srv_linux_thread_db=yes ;; @@ -137,6 +144,7 @@ case "${target}" in srv_regobj=reg-m68k.o fi srv_tgtobj="linux-low.o linux-osdata.o linux-m68k-low.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_linux_usrregs=yes srv_linux_regsets=yes srv_linux_thread_db=yes @@ -147,6 +155,7 @@ case "${target}" in srv_regobj=reg-m68k.o fi srv_tgtobj="linux-low.o linux-osdata.o linux-m68k-low.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_linux_usrregs=yes srv_linux_regsets=yes srv_linux_thread_db=yes @@ -156,6 +165,7 @@ case "${target}" in srv_regobj="${srv_regobj} mips64-linux.o" srv_regobj="${srv_regobj} mips64-dsp-linux.o" srv_tgtobj="linux-low.o linux-osdata.o linux-mips-low.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_xmlfiles="mips-linux.xml" srv_xmlfiles="${srv_xmlfiles} mips-dsp-linux.xml" srv_xmlfiles="${srv_xmlfiles} mips-cpu.xml" @@ -188,6 +198,7 @@ case "${target}" in srv_regobj="${srv_regobj} powerpc-isa205-altivec64l.o" srv_regobj="${srv_regobj} powerpc-isa205-vsx64l.o" srv_tgtobj="linux-low.o linux-osdata.o linux-ppc-low.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_xmlfiles="rs6000/powerpc-32l.xml" srv_xmlfiles="${srv_xmlfiles} rs6000/powerpc-altivec32l.xml" srv_xmlfiles="${srv_xmlfiles} rs6000/powerpc-cell32l.xml" @@ -230,6 +241,7 @@ case "${target}" in srv_regobj="${srv_regobj} s390x-linux64v1.o" srv_regobj="${srv_regobj} s390x-linux64v2.o" srv_tgtobj="linux-low.o linux-osdata.o linux-s390-low.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_xmlfiles="s390-linux32.xml" srv_xmlfiles="${srv_xmlfiles} s390-linux32v1.xml" srv_xmlfiles="${srv_xmlfiles} s390-linux32v2.xml" @@ -250,12 +262,14 @@ case "${target}" in ;; sh*-*-linux*) srv_regobj=reg-sh.o srv_tgtobj="linux-low.o linux-osdata.o linux-sh-low.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_linux_usrregs=yes srv_linux_regsets=yes srv_linux_thread_db=yes ;; sparc*-*-linux*) srv_regobj=reg-sparc64.o srv_tgtobj="linux-low.o linux-osdata.o linux-sparc-low.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_linux_regsets=yes srv_linux_thread_db=yes ;; @@ -272,12 +286,14 @@ case "${target}" in srv_xmlfiles="${srv_xmlfiles} tic6x-gp.xml" srv_xmlfiles="${srv_xmlfiles} tic6x-c6xp.xml" srv_tgtobj="linux-low.o linux-osdata.o linux-tic6x-low.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_linux_regsets=yes srv_linux_usrregs=yes srv_linux_thread_db=yes ;; x86_64-*-linux*) srv_regobj="$srv_amd64_linux_regobj $srv_i386_linux_regobj" srv_tgtobj="linux-low.o linux-osdata.o linux-x86-low.o i386-low.o i387-fp.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_xmlfiles="$srv_i386_linux_xmlfiles $srv_amd64_linux_xmlfiles" srv_linux_usrregs=yes # This is for i386 progs. srv_linux_regsets=yes @@ -292,6 +308,7 @@ case "${target}" in xtensa*-*-linux*) srv_regobj=reg-xtensa.o srv_tgtobj="linux-low.o linux-osdata.o linux-xtensa-low.o linux-procfs.o" + srv_tgtobj="${srv_tgtobj} linux-ptrace.o" srv_linux_regsets=yes ;; *) echo "Error: target not supported by gdbserver." diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 997e5a009c4..06ec5763c62 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -660,10 +660,10 @@ linux_attach_lwp_1 (unsigned long lwpid, int initial) fflush (stderr); return; } - else - /* If we fail to attach to a process, report an error. */ - error ("Cannot attach to lwp %ld: %s (%d)\n", lwpid, - strerror (errno), errno); + + /* If we fail to attach to a process, report an error. */ + error ("Cannot attach to lwp %ld: %s (%d)\n", lwpid, + strerror (errno), errno); } if (initial) diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index e3a5e9d973f..442d6f40a47 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -2465,37 +2465,6 @@ linux_handle_extended_wait (struct lwp_info *lp, int status, _("unknown ptrace event %d"), event); } -/* Return non-zero if LWP is a zombie. */ - -static int -linux_lwp_is_zombie (long lwp) -{ - char buffer[MAXPATHLEN]; - FILE *procfile; - int retval; - int have_state; - - xsnprintf (buffer, sizeof (buffer), "/proc/%ld/status", lwp); - procfile = fopen (buffer, "r"); - if (procfile == NULL) - { - warning (_("unable to open /proc file '%s'"), buffer); - return 0; - } - - have_state = 0; - while (fgets (buffer, sizeof (buffer), procfile) != NULL) - if (strncmp (buffer, "State:", 6) == 0) - { - have_state = 1; - break; - } - retval = (have_state - && strcmp (buffer, "State:\tZ (zombie)\n") == 0); - fclose (procfile); - return retval; -} - /* Wait for LP to stop. Returns the wait status, or 0 if the LWP has exited. */ @@ -2549,10 +2518,10 @@ wait_lwp (struct lwp_info *lp) This is racy, what if the tgl becomes a zombie right after we check? Therefore always use WNOHANG with sigsuspend - it is equivalent to - waiting waitpid but the linux_lwp_is_zombie is safe this way. */ + waiting waitpid but linux_proc_pid_is_zombie is safe this way. */ if (GET_PID (lp->ptid) == GET_LWP (lp->ptid) - && linux_lwp_is_zombie (GET_LWP (lp->ptid))) + && linux_proc_pid_is_zombie (GET_LWP (lp->ptid))) { thread_dead = 1; if (debug_linux_nat) @@ -3499,7 +3468,7 @@ check_zombie_leaders (void) /* Check if there are other threads in the group, as we may have raced with the inferior simply exiting. */ && num_lwps (inf->pid) > 1 - && linux_lwp_is_zombie (inf->pid)) + && linux_proc_pid_is_zombie (inf->pid)) { if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, -- 2.30.2