From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24661 invoked by alias); 7 Mar 2013 09:41:09 -0000 Received: (qmail 24648 invoked by uid 22791); 7 Mar 2013 09:41:08 -0000 X-SWARE-Spam-Status: No, hits=-8.1 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,KHOP_THREADED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mga03.intel.com (HELO mga03.intel.com) (143.182.124.21) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 07 Mar 2013 09:41:00 +0000 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101.ch.intel.com with ESMTP; 07 Mar 2013 01:40:58 -0800 X-ExtLoop1: 1 Received: from irsmsx104.ger.corp.intel.com ([163.33.3.159]) by azsmga001.ch.intel.com with ESMTP; 07 Mar 2013 01:40:57 -0800 Received: from irsmsx152.ger.corp.intel.com (163.33.192.66) by IRSMSX104.ger.corp.intel.com (163.33.3.159) with Microsoft SMTP Server (TLS) id 14.1.355.2; Thu, 7 Mar 2013 09:40:54 +0000 Received: from irsmsx102.ger.corp.intel.com ([169.254.2.244]) by IRSMSX152.ger.corp.intel.com ([169.254.6.185]) with mapi id 14.01.0355.002; Thu, 7 Mar 2013 09:40:54 +0000 From: "Metzger, Markus T" To: Jan Kratochvil CC: "gdb-patches@sourceware.org" , "markus.t.metzger@gmail.com" , "Himpel, Christian" Subject: RE: Crash of GDB with gdbserver btrace enabled [Re: [patch v9 00/23] branch tracing support for Atom] Date: Thu, 07 Mar 2013 09:41:00 -0000 Message-ID: References: <1362416770-19750-1-git-send-email-markus.t.metzger@intel.com> <20130306124334.GA29994@host2.jankratochvil.net> <20130306170622.GA25771@host2.jankratochvil.net> <20130307090632.GA11095@host2.jankratochvil.net> In-Reply-To: <20130307090632.GA11095@host2.jankratochvil.net> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: 2013-03/txt/msg00268.txt.bz2 > -----Original Message----- > From: Jan Kratochvil [mailto:jan.kratochvil@redhat.com] > Sent: Thursday, March 07, 2013 10:07 AM > > I'm not quite sure what the OS will do if tracing is requested twice fo= r the same > > thread, i.e. repeated "record stop" followed by "record btrace" . We m= ay get > > an error or we may get a second buffer, thus leaking resources (i.e. th= e mmapped > > trace buffer). We will need another target method to disable branch tr= acing > > that is called by the "record stop" command. >=20 > Yes, thanks for catching it, "record stop" needs to call real btrace_disa= ble > before unpushing the target. >=20 >=20 > > In a gdbserver --multi session, I would expect that we're leaking the m= mapped trace > > buffer also on re-run. >=20 > During re-run the first process gets killed first, so btrace_clear on the= GDB > side is appropriate in such case. The problem is that your patch wouldn't try to actually disable tracing on = the target. Gdbserver would still have the trace buffer mmapped. I don't know if the O= S can unmap those buffers when the traced process goes away - the buffers are own= ed by another process that is still running. This does not only affect re-run. We should have the same issue when a pth= read is joined. > @@ -447,6 +447,12 @@ btrace_clear (struct thread_info *tp) >=20 > btinfo =3D &tp->btrace; >=20 > + if (btinfo->target !=3D NULL) > + { > + target_clear_btrace (btinfo->target); > + btinfo->target =3D NULL; > + } This is also something we don't want to do. It would disable tracing when = we just want to update the trace. I have a patch that adds another disable path similar to your patch. That o= ther path is used in clear_thread_inferior_resources. So in to_close, we first = try to disable branch tracing normally. Should we realize that the target is gone= , GDB will pop all targets, discard all threads, and throw an error. Discard all threads will now use the teardown path instead of the disable p= ath. The error will abort the thread traversal in to_close. The remaining problem is that this will leak branch trace buffers for joined pthreads in the remote case. Is there a reliable way of determining whether the target connection is dow= n? If there is, I could disable normally as long as the target connection is u= p and only leak resources when the connection is already down. I might not even n= eed the second disable path in that case. Another approach would be to change pop_target to unpush the top target instead of just closing it. This would prevent btrace from finding a targe= t to disable tracing and all I would need to do is remove the tcomplain call in target_disable_btrace. This would be quite elegant but I have no clue about the side effects this might have. > On the gdbserver side there is linux_disable_btrace still called: > #0 linux_disable_btrace (tinfo=3D0x66fd40) at ../common/linux-btrace.c:5= 09 > #1 in remove_thread (thread=3D0x66f900) at inferiors.c:165 > #2 in delete_lwp (lwp=3D0x66f7d0) at linux-low.c:334 > #3 in delete_lwp_callback (entry=3D0x66f7d0, proc=3D0x66f660) at linux-l= ow.c:1234 > #4 in find_inferior (list=3D0x666540 , func=3D0x425c61 , arg=3D0x66f660) at inferiors.c:185 > #5 in linux_mourn (process=3D0x66f660) at linux-low.c:1248 > #6 in linux_kill (pid=3D28282) at linux-low.c:1058 > #7 in kill_inferior (pid=3D28282) at target.c:190 > #8 in handle_v_kill (own_buf=3D0x667370 "vKill;6e7a") at server.c:2273 > #9 in handle_v_requests (own_buf=3D0x667370 "vKill;6e7a", packet_len=3D1= 0, new_packet_len=3D0x7fffffffd7c8) at server.c:2345 > #10 in process_serial_event () at server.c:3484 >=20 > So I find that OK. >=20 >=20 > > I think this can be handled with an appropriate to_create_inferior meth= od. >=20 > I do not see a reason for that hook - could you be more specific? I was only thinking about re-running an already running process. But the i= ssue is more general and thus requires a more general solution. Regards, Markus. Intel GmbH Dornacher Strasse 1 85622 Feldkirchen/Muenchen, Deutschland Sitz der Gesellschaft: Feldkirchen bei Muenchen Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk Registergericht: Muenchen HRB 47456 Ust.-IdNr./VAT Registration No.: DE129385895 Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052