From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5226 invoked by alias); 21 Apr 2012 02:22:47 -0000 Received: (qmail 5209 invoked by uid 22791); 21 Apr 2012 02:22:46 -0000 X-SWARE-Spam-Status: No, hits=-4.7 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-pb0-f41.google.com (HELO mail-pb0-f41.google.com) (209.85.160.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 21 Apr 2012 02:22:14 +0000 Received: by pbcup15 with SMTP id up15so1772363pbc.0 for ; Fri, 20 Apr 2012 19:22:13 -0700 (PDT) Received: by 10.68.189.34 with SMTP id gf2mr1228511pbc.132.1334974933752; Fri, 20 Apr 2012 19:22:13 -0700 (PDT) Received: from [192.168.1.128] ([115.195.157.111]) by mx.google.com with ESMTPS id d4sm7006857pbr.32.2012.04.20.19.22.10 (version=SSLv3 cipher=OTHER); Fri, 20 Apr 2012 19:22:12 -0700 (PDT) Message-ID: <4F921A25.1020106@gmail.com> Date: Sat, 21 Apr 2012 03:06:00 -0000 From: asmwarrior User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 To: Marc Khouzam , gdb-patches@sourceware.org Subject: Re: [Patch] Fix for MI selecting an exited thread References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed 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-04/txt/msg00709.txt.bz2 On 2012-4-21 3:57, Marc Khouzam wrote: > 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: > ======================= >> 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=1, argv=0xbffff794) at hello.cpp:8 > 8 while(1) { } > (gdb) interpreter-exec mi "-exec-continue --thread-group i1" > ^error,msg="Cannot execute this command without a live selected thread." > > (gdb) inf thr > Id Target Id Frame > 1 Thread 0xb7fe7b30 (LWP 4641) main (argc=1, argv=0xbffff794) at hello.cpp:8 > The current thread has terminated. See `help thread'. > > > Patch: > ===== > 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 > =================================================================== > 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 != 0) > - tp = any_thread_of_process (inf->pid); > + tp = any_live_thread_of_process (inf->pid); > switch_to_thread (tp ? tp->ptid : null_ptid); > set_current_program_space (inf->pspace); > } > I just read this in gdbthread.h /* Returns any thread of process PID. */ extern struct thread_info *any_thread_of_process (int pid); /* 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); What does "Give preference for non executing threads"? Any way to give preference for executing threads? It can been see in thread.c, the else clause just return the non executing thread. struct thread_info * any_live_thread_of_process (int pid) { struct thread_info *tp; struct thread_info *tp_executing = NULL; for (tp = thread_list; tp; tp = tp->next) if (tp->state != THREAD_EXITED && ptid_get_pid (tp->ptid) == pid) { if (tp->executing) tp_executing = tp; else return tp; } return tp_executing; } Yuanhui Zhang