From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2006 invoked by alias); 6 Dec 2010 13:05:47 -0000 Received: (qmail 1998 invoked by uid 22791); 6 Dec 2010 13:05:47 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,TW_CP,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from sibelius.xs4all.nl (HELO glazunov.sibelius.xs4all.nl) (83.163.83.176) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 06 Dec 2010 13:05:41 +0000 Received: from glazunov.sibelius.xs4all.nl (kettenis@localhost [127.0.0.1]) by glazunov.sibelius.xs4all.nl (8.14.3/8.14.3) with ESMTP id oB6D5PF6019209; Mon, 6 Dec 2010 14:05:25 +0100 (CET) Received: (from kettenis@localhost) by glazunov.sibelius.xs4all.nl (8.14.3/8.14.3/Submit) id oB6D5NMi021251; Mon, 6 Dec 2010 14:05:23 +0100 (CET) Date: Mon, 06 Dec 2010 13:05:00 -0000 Message-Id: <201012061305.oB6D5NMi021251@glazunov.sibelius.xs4all.nl> From: Mark Kettenis To: jan.kratochvil@redhat.com CC: gdb-patches@sourceware.org In-reply-to: <20101206111300.GC27176@host0.dyn.jankratochvil.net> (message from Jan Kratochvil on Mon, 6 Dec 2010 12:13:01 +0100) Subject: Re: [patch 2/4] hw watchpoints across fork() References: <20101206111300.GC27176@host0.dyn.jankratochvil.net> 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: 2010-12/txt/msg00047.txt.bz2 > Date: Mon, 6 Dec 2010 12:13:01 +0100 > From: Jan Kratochvil > > --- a/gdb/i386-nat.c > +++ b/gdb/i386-nat.c > @@ -220,16 +220,50 @@ static int i386_handle_nonaligned_watchpoint (i386_wp_op_t what, > > /* Implementation. */ > > +/* Per-inferior data key. */ > +static const struct inferior_data *i386_inferior_data; > + > +struct i386_inferior_data > + { > + /* Copy of i386 hardware debug registers for performance reasons. */ > + struct dr_mirror dr_mirror; > + }; > + > +static struct i386_inferior_data * > +i386_inferior_data_get (void) > +{ > + static struct i386_inferior_data inf_data_local; > + struct inferior *inf = current_inferior (); > + struct i386_inferior_data *inf_data = &inf_data_local; > + static struct i386_inferior_data *detached_inf_data; > + static int detached_inf_pid = -1; The whole dance with inf_data seems unecessarily complicated to me. Why not... > + > + if (inf->pid != ptid_get_pid (inferior_ptid)) > + { > + if (detached_inf_pid != ptid_get_pid (inferior_ptid)) > + { > + xfree (detached_inf_data); > + detached_inf_pid = ptid_get_pid (inferior_ptid); > + detached_inf_data = xmalloc (sizeof (*detached_inf_data)); Huh, free and immediately malloc? > + > + /* Forked processes get a copy of the debug registers. */ > + memcpy (detached_inf_data, inf_data, sizeof (*detached_inf_data)); > + } > + > + gdb_assert (detached_inf_data != NULL); > + inf_data = detached_inf_data; Simply return detached_inf_data here. > + } > + > + return inf_data; And return &inf_data_local here? But why are you returning pointers to static storage in the first place? I'm abviously missing the point of this function. Can you explain?