From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18160 invoked by alias); 21 Apr 2012 03:12:06 -0000 Received: (qmail 18149 invoked by uid 22791); 21 Apr 2012 03:12:04 -0000 X-SWARE-Spam-Status: No, hits=-3.9 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Received: from imr4.ericy.com (HELO imr4.ericy.com) (198.24.6.9) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 21 Apr 2012 03:11:27 +0000 Received: from eusaamw0706.eamcs.ericsson.se ([147.117.20.31]) by imr4.ericy.com (8.14.3/8.14.3/Debian-9.1ubuntu1) with ESMTP id q3L3BPe0009131; Fri, 20 Apr 2012 22:11:26 -0500 Received: from EUSAACMS0703.eamcs.ericsson.se ([169.254.1.158]) by eusaamw0706.eamcs.ericsson.se ([147.117.20.31]) with mapi; Fri, 20 Apr 2012 23:11:19 -0400 From: Marc Khouzam To: asmwarrior , "gdb-patches@sourceware.org" Date: Sat, 21 Apr 2012 10:12:00 -0000 Subject: RE: [Patch] Fix for MI selecting an exited thread Message-ID: References: ,<4F921A25.1020106@gmail.com> In-Reply-To: <4F921A25.1020106@gmail.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-IsSubscribed: yes 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-04/txt/msg00711.txt.bz2 > > Hi, > > > > Eclipse is sometimes hitting what I feel is a GDB/MI bug. > > When trying to resume an entire inferior in all-stop, > > GDB can end up selecting a thread that does not exist anymore. > > > > The below session shows a program that starts a second thread > > that exists immediately. Then, I interrupt the inferior with ^C > > and try to resume it using an MI command. Because I don't specify > > an actual thread but the entire process (thread-group), MI randomly > > chooses a thread to use, in this case, the exited thread. > > > > I suggest that MI should only choose a live thread when randomly > > selecting one. The below patch does this with no regressions. > > > > Ok? > > > > > > Session showing the bug: > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > >> gdb.7.5 a.out > > GNU gdb (GDB) 7.4.50.20120420-cvs > > (gdb) l > > 1 #include > > 2 > > 3 void* run(void* arg) { return 0; } > > 4 > > 5 int main(int argc, char** argv) { > > 6 pthread_t tid; > > 7 pthread_create(&tid, NULL,&run, NULL); > > 8 while(1) { } > > 9 } > > (gdb) r > > Starting program: /home/lmckhou/testing/a.out > > [Thread debugging using libthread_db enabled] > > Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1". > > [New Thread 0xb7fe5b70 (LWP 4645)] > > [Thread 0xb7fe5b70 (LWP 4645) exited] > > ^C > > Program received signal SIGINT, Interrupt. > > main (argc=3D1, argv=3D0xbffff794) at hello.cpp:8 > > 8 while(1) { } > > (gdb) interpreter-exec mi "-exec-continue --thread-group i1" > > ^error,msg=3D"Cannot execute this command without a live selected threa= d." > > > > (gdb) inf thr > > Id Target Id Frame > > 1 Thread 0xb7fe7b30 (LWP 4641) main (argc=3D1, argv=3D0xbffff794)= at hello.cpp:8 > > The current thread has terminated. See `help thread'. > > > > > > Patch: > > =3D=3D=3D=3D=3D > > 2012-04-20 Marc Khouzam > > > > * mi/mi-main.c (mi_cmd_execute): Choose a live thread not just > > any thread. > > > > ### Eclipse Workspace Patch 1.0 > > #P src > > Index: gdb/mi/mi-main.c > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > RCS file: /cvs/src/src/gdb/mi/mi-main.c,v > > retrieving revision 1.215 > > diff -u -r1.215 mi-main.c > > --- gdb/mi/mi-main.c 27 Mar 2012 19:08:37 -0000 1.215 > > +++ gdb/mi/mi-main.c 20 Apr 2012 19:47:35 -0000 > > @@ -2066,7 +2066,7 @@ > > provide --thread if it wishes to operate on a specific > > thread. */ > > if (inf->pid !=3D 0) > > - tp =3D any_thread_of_process (inf->pid); > > + tp =3D any_live_thread_of_process (inf->pid); > > switch_to_thread (tp ? tp->ptid : null_ptid); > > set_current_program_space (inf->pspace); > > } > > >=20 > I just read this in gdbthread.h >=20 > /* Returns any thread of process PID. */ > extern struct thread_info *any_thread_of_process (int pid); >=20 > /* Returns any non-exited thread of process PID, giving preference for > not executing threads. */ > extern struct thread_info *any_live_thread_of_process (int pid); >=20 > What does "Give preference for non executing threads"? > Any way to give preference for executing threads? >=20 > It can been see in thread.c, the else clause just return the non executin= g thread. Yes, the else clause is giving preference to the not executing thread. If = there are no such thread, the method returns an executing thread. This method behave li= kes this to solve the problem stated in: http://sourceware.org/ml/gdb-patches/2011-04/msg00326.html >=20 > struct thread_info * > any_live_thread_of_process (int pid) > { > struct thread_info *tp; > struct thread_info *tp_executing =3D NULL; >=20 > for (tp =3D thread_list; tp; tp =3D tp->next) > if (tp->state !=3D THREAD_EXITED && ptid_get_pid (tp->ptid) =3D=3D p= id) > { > if (tp->executing) > tp_executing =3D tp; > else > return tp; > } >=20 > return tp_executing; > } >=20 > Yuanhui Zhang