From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20538 invoked by alias); 15 Aug 2008 14:00:52 -0000 Received: (qmail 20529 invoked by uid 22791); 15 Aug 2008 14:00:51 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 15 Aug 2008 14:00:15 +0000 Received: (qmail 30254 invoked from network); 15 Aug 2008 14:00:13 -0000 Received: from unknown (HELO localhost) (vladimir@127.0.0.2) by mail.codesourcery.com with ESMTPA; 15 Aug 2008 14:00:13 -0000 From: Vladimir Prus To: Mark Kettenis Subject: Re: [RFC] Kill pthread_ops_hack Date: Fri, 15 Aug 2008 14:00:00 -0000 User-Agent: KMail/1.9.9 Cc: gdb-patches@sources.redhat.com References: <200808151715.55875.vladimir@codesourcery.com> <200808151342.m7FDgHru018919@brahms.sibelius.xs4all.nl> In-Reply-To: <200808151342.m7FDgHru018919@brahms.sibelius.xs4all.nl> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200808151800.05885.vladimir@codesourcery.com> 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: 2008-08/txt/msg00405.txt.bz2 On Friday 15 August 2008 17:42:17 Mark Kettenis wrote: > > From: Vladimir Prus > > Date: Fri, 15 Aug 2008 17:15:55 +0400 > > > > > > Whenever a target that uses ptrace is created, GDB calls > > inf_ptrace_target, and then augments the result with whatever > > methods are necessary for the current OS, CPU, etc. However, when > > inf_ptrace_target is called, the result is stored in a global > > variable ptrace_ops_hack, which is then used by inf-ptrace.c in a > > few places. Of course, having a variable named whatever_hack in GDB > > codebase is already bad, but this design also means that we have > > have only one pthread-based target active at a time, which does not > > seem like a good thing. > > > > In fact, pthread_ops_hack is a consequence of current design of > > target stack. When we do 'run', the linux target is not pushed yet, > > and find_default_create_inferior looks for a target, and calls its > > to_create_inferior method. As soon as we create inferiour, we need > > to push the target on stack, so that further operations will apply > > to now-existing inferiour. But to_create_inferior is not passed the > > struct target_ops pointer, so it does not know what to push. This > > patch makes to_create_inferiour and few other methods, take struct > > target_ops pointer, and kills pthread_ops_hack. > > Looks like you're confusing ptrace and pthreads here. Only in the text of the message :-) > > I have only converted few targets -- linux and remote. Converting > > others will be a mechanical task for adding a parameter to function, > > but before I go on with that -- anybody has objections to the > > general direction of this patch? > > No this is the obvious solution. However: > > > static void > > -inf_ptrace_him (int pid) > > +inf_ptrace_create_inferior (struct target_ops *ops, > > + char *exec_file, char *allargs, char **env, > > + int from_tty) > > { > > - push_target (ptrace_ops_hack); > > + int pid = fork_inferior (exec_file, allargs, env, inf_ptrace_me, NULL, > > + NULL, NULL); > > Could you please not write code like that? The stuff fork_inferior() > does goes way beyond what's necessary to initialize pid. Better write > it like: > > { > int pid; > > pid = fork_inferior(exec_file, ...); > } OK. - Volodya