From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16570 invoked by alias); 9 Dec 2002 22:14:57 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 16562 invoked from network); 9 Dec 2002 22:14:55 -0000 Received: from unknown (HELO tripod-int.labs.agilent.com) (192.25.140.133) by sources.redhat.com with SMTP; 9 Dec 2002 22:14:55 -0000 Received: from thing1.labs.agilent.com (thing1.labs.agilent.com [130.29.252.18]) by tripod-int.labs.agilent.com (8.12.6/8.12.6/Tripod Sendmail Config v01.02 2002/09/24) with ESMTP id gB9MEt9J029761 for ; Mon, 9 Dec 2002 14:14:55 -0800 Received: from alex2.labs.agilent.com (alex2.labs.agilent.com [130.29.252.56]) by thing1.labs.agilent.com (8.12.6/8.12.6/Agilent Labs Mail Hub v 01.02 2002/02/06) with SMTP id gB9MEsho022289 for ; Mon, 9 Dec 2002 14:14:54 -0800 Received: from 130.29.252.56 by alex2.labs.agilent.com (InterScan E-Mail VirusWall NT); Mon, 09 Dec 2002 14:14:54 -0800 Received: by ALEX2 with Internet Mail Service (5.5.2656.59) id ; Mon, 9 Dec 2002 14:14:54 -0800 Message-ID: From: glenn_engel@agilent.com To: gdb-patches@sources.redhat.com Subject: patch to gdbserver for names instead of pid numbers Date: Mon, 09 Dec 2002 14:33:00 -0000 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C29FD0.55E67A09" X-SW-Source: 2002-12/txt/msg00300.txt.bz2 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C29FD0.55E67A09 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C29FD0.55E67A09" ------_=_NextPart_001_01C29FD0.55E67A09 Content-Type: text/plain; charset="iso-8859-1" Content-length: 543 Attached is a patch to gdbserver to allow the remote server to attach to a process by executable name rather than by pid number. It chooses the 'first' process name that matches, assuming it to be the group leader of a multi-threaded application. I found this to be extremely helpful in repeated use of gdbserver. 2002-12-09 Glenn Engel glenne@engel.org * server.c (main): Allow process name in addition to PID number -- Glenn glenn_engel@agilent.com / Agilent Laboratories / NN7N / 425-335-2066 ------_=_NextPart_001_01C29FD0.55E67A09 Content-Type: text/html; charset="iso-8859-1" Content-length: 1383
Attached is a patch to gdbserver to allow the remote server to attach to a process by executable name rather than by pid number.  It chooses the 'first' process name that matches, assuming it to be the group leader of a multi-threaded application.  I found this to be extremely helpful in repeated use of gdbserver.
 
2002-12-09  Glenn Engel glenne@engel.org
 
        * server.c (main): Allow process name in addition to PID number

--
Glenn

glenn_engel@agilent.com / Agilent Laboratories / NN7N / 425-335-2066

 
------_=_NextPart_001_01C29FD0.55E67A09-- ------_=_NextPart_000_01C29FD0.55E67A09 Content-Type: application/octet-stream; name="gdbserver.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="gdbserver.patch" Content-length: 6929 *** gdb/gdbserver/Makefile.in.orig Mon Dec 9 13:57:29 2002=0A= --- gdb/gdbserver/Makefile.in Mon Dec 9 14:03:34 2002=0A= ***************=0A= *** 116,122 ****=0A= SFILES =3D $(srcdir)/low-hppabsd.c $(srcdir)/low-linux.c $(srcdir)/low-ly= nx.c \=0A= $(srcdir)/low-nbsd.c $(srcdir)/low-sim.c $(srcdir)/low-sparc.c \=0A= $(srcdir)/low-sun3.c $(srcdir)/utils.c $(srcdir)/server.c \=0A= ! $(srcdir)/remote-utils.c=0A= =20=20=0A= DEPFILES =3D @GDBSERVER_DEPFILES@=0A= =20=20=0A= --- 116,122 ----=0A= SFILES =3D $(srcdir)/low-hppabsd.c $(srcdir)/low-linux.c $(srcdir)/low-ly= nx.c \=0A= $(srcdir)/low-nbsd.c $(srcdir)/low-sim.c $(srcdir)/low-sparc.c \=0A= $(srcdir)/low-sun3.c $(srcdir)/utils.c $(srcdir)/server.c \=0A= ! $(srcdir)/remote-utils.c ($srcdir)/findpid.c=0A= =20=20=0A= DEPFILES =3D @GDBSERVER_DEPFILES@=0A= =20=20=0A= ***************=0A= *** 124,130 ****=0A= TAGFILES =3D $(SOURCES) ${HFILES} ${ALLPARAM} ${POSSLIBS}=20=0A= =20=20=0A= OBS =3D inferiors.o regcache.o remote-utils.o server.o signals.o target.o= \=0A= ! utils.o \=0A= mem-break.o \=0A= $(DEPFILES)=0A= GDBSERVER_LIBS =3D @GDBSERVER_LIBS@=0A= --- 124,130 ----=0A= TAGFILES =3D $(SOURCES) ${HFILES} ${ALLPARAM} ${POSSLIBS}=20=0A= =20=20=0A= OBS =3D inferiors.o regcache.o remote-utils.o server.o signals.o target.o= \=0A= ! utils.o findpid.o \=0A= mem-break.o \=0A= $(DEPFILES)=0A= GDBSERVER_LIBS =3D @GDBSERVER_LIBS@=0A= ***************=0A= *** 245,250 ****=0A= --- 245,251 ----=0A= proc-service.o: proc-service.c $(server_h) $(gdb_proc_service_h)=0A= regcache.o: regcache.c $(server_h) $(regdef_h)=0A= remote-utils.o: remote-utils.c terminal.h $(server_h)=0A= + findpid.o: findpid.c findpid.h=0A= server.o: server.c $(server_h)=0A= target.o: target.c $(server_h)=0A= thread-db.o: thread-db.c $(server_h) $(gdb_proc_service_h)=0A= *** gdb/gdbserver/server.c.orig Mon Dec 9 13:24:16 2002=0A= --- gdb/gdbserver/server.c Mon Dec 9 13:51:55 2002=0A= ***************=0A= *** 20,25 ****=0A= --- 20,26 ----=0A= Boston, MA 02111-1307, USA. */=0A= =20=20=0A= #include "server.h"=0A= + #include "findpid.h"=0A= =20=20=0A= #include =0A= #include =0A= ***************=0A= *** 131,137 ****=0A= gdbserver_usage (void)=0A= {=0A= error ("Usage:\tgdbserver COMM PROG [ARGS ...]\n"=0A= ! "\tgdbserver COMM --attach PID\n"=0A= "\n"=0A= "COMM may either be a tty device (for serial debugging), or \n"=0A= "HOST:PORT to listen for a TCP connection.\n");=0A= --- 132,138 ----=0A= gdbserver_usage (void)=0A= {=0A= error ("Usage:\tgdbserver COMM PROG [ARGS ...]\n"=0A= ! "\tgdbserver COMM --attach PID|NAME\n"=0A= "\n"=0A= "COMM may either be a tty device (for serial debugging), or \n"=0A= "HOST:PORT to listen for a TCP connection.\n");=0A= ***************=0A= *** 162,169 ****=0A= {=0A= if (argc =3D=3D 4=0A= && argv[3] !=3D '\0'=0A= ! && (pid =3D strtoul (argv[3], &arg_end, 10)) !=3D 0=0A= ! && *arg_end =3D=3D '\0')=0A= {=0A= ;=0A= }=0A= --- 163,170 ----=0A= {=0A= if (argc =3D=3D 4=0A= && argv[3] !=3D '\0'=0A= ! && (((pid =3D strtoul (argv[3], &arg_end, 10)) !=3D 0 && *arg_end =3D= =3D '\0')=0A= ! || ((pid =3D find_pid_by_name(argv[3])) !=3D -1)))=0A= {=0A= ;=0A= }=0A= *** /dev/null Thu Aug 30 13:30:55 2001=0A= --- gdb/gdbserver/findpid.h Mon Dec 9 14:02:55 2002=0A= ***************=0A= *** 0 ****=0A= --- 1,4 ----=0A= + #ifndef FINDPID_H=0A= + #include =0A= + extern pid_t find_pid_by_name( char* pidName);=0A= + #endif /* FINDPID_H */=0A= *** /dev/null Thu Aug 30 13:30:55 2001=0A= --- gdb/gdbserver/findpid.c Mon Dec 9 13:30:55 2002=0A= ***************=0A= *** 0 ****=0A= --- 1,95 ----=0A= + /* leveraged from busybox source */=0A= + /*=0A= + * Utility routines.=0A= + *=0A= + * Copyright (C) tons of folks. Tracking down who wrote what=0A= + * isn't something I'm going to worry about... If you wrote something=0A= + * here, please feel free to acknowledge your work.=0A= + *=0A= + * This program is free software; you can redistribute it and/or modify= =0A= + * it under the terms of the GNU General Public License as published by= =0A= + * the Free Software Foundation; either version 2 of the License, or=0A= + * (at your option) any later version.=0A= + *=0A= + * This program is distributed in the hope that it will be useful,=0A= + * but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU=0A= + * General Public License for more details.=0A= + *=0A= + * You should have received a copy of the GNU General Public License=0A= + * along with this program; if not, write to the Free Software=0A= + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US= A=0A= + *=0A= + * Based in part on code from sash, Copyright (c) 1999 by David I. Bell= =20=0A= + * Permission has been granted to redistribute this code under the GPL.= =0A= + *=0A= + */=0A= +=20=0A= + #include =0A= + #include =0A= + #include =0A= + #include =0A= +=20=0A= + #define READ_BUF_SIZE 50=0A= +=20=0A= +=20=0A= + /* find_pid_by_name()=0A= + *=20=20=0A= + * This finds the pid of the specified process.=0A= + * Currently, it's implemented by rummaging through=20=0A= + * the proc filesystem.=0A= + *=0A= + * Returns the first pid matching 'pidName'=0A= + */=0A= + extern pid_t find_pid_by_name( char* pidName)=0A= + {=0A= + DIR *dir;=0A= + struct dirent *next;=0A= +=20=0A= + dir =3D opendir("/proc");=0A= + if (!dir)=0A= + perror("Cannot open /proc");=0A= +=20=09=0A= + while ((next =3D readdir(dir)) !=3D NULL) {=0A= + FILE *status;=0A= + char filename[READ_BUF_SIZE];=0A= + char buffer[READ_BUF_SIZE];=0A= + char name[READ_BUF_SIZE];=0A= +=20=0A= + /* Must skip ".." since that is outside /proc */=0A= + if (strcmp(next->d_name, "..") =3D=3D 0)=0A= + continue;=0A= +=20=0A= + /* If it isn't a number, we don't want it */=0A= + if (!isdigit(*next->d_name))=0A= + continue;=0A= +=20=0A= + sprintf(filename, "/proc/%s/status", next->d_name);=0A= + if (! (status =3D fopen(filename, "r")) ) {=0A= + continue;=0A= + }=0A= + if (fgets(buffer, READ_BUF_SIZE-1, status) =3D=3D NULL) {=0A= + fclose(status);=0A= + continue;=0A= + }=0A= + fclose(status);=0A= +=20=0A= + /* Buffer should contain a string like "Name: binary_name" */=0A= + sscanf(buffer, "%*s %s", name);=0A= + if (strcmp(name, pidName) =3D=3D 0)=20=0A= + return strtol(next->d_name, NULL, 0);=0A= + }=0A= +=20=0A= + return -1;=0A= + }=0A= +=20=0A= + #ifdef STANDALONE_TEST_FINDPID=0A= + int main(int argc, char *argv[])=0A= + {=0A= + pid_t pid;=0A= + pid =3D find_pid_by_name(argv[1]);=0A= +=20=0A= + printf("%d \n", pid);=0A= +=20=09=09=0A= + }=0A= + #endif=0A= ------_=_NextPart_000_01C29FD0.55E67A09--