From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 111434 invoked by alias); 7 May 2015 02:53:46 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 111425 invoked by uid 89); 7 May 2015 02:53:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 07 May 2015 02:53:44 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id F18A28E6F0 for ; Thu, 7 May 2015 02:53:42 +0000 (UTC) Received: from freie.home (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t472remt028234 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 6 May 2015 22:53:42 -0400 Received: from livre.home (livre.home [172.31.160.2]) by freie.home (8.14.8/8.14.8) with ESMTP id t472rb75011723; Wed, 6 May 2015 23:53:38 -0300 From: Alexandre Oliva To: Jan Kratochvil Cc: Phil Muldoon , gdb@sourceware.org Subject: Re: compile: objfiles lifetime UI References: <20150429135735.GA16974@host1.jankratochvil.net> <55420463.10400@redhat.com> <20150430105349.GA6260@host1.jankratochvil.net> <20150506122637.GA21147@host1.jankratochvil.net> Date: Thu, 07 May 2015 02:53:00 -0000 In-Reply-To: <20150506122637.GA21147@host1.jankratochvil.net> (Jan Kratochvil's message of "Wed, 6 May 2015 14:26:37 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2015-05/txt/msg00008.txt.bz2 On May 6, 2015, Jan Kratochvil wrote: > On Thu, 30 Apr 2015 12:53:49 +0200, Jan Kratochvil wrote: >> What about that 2nd case example of: >> (gdb) compile code str = "bar"; >> That can be also typed as the 1st case: >> (gdb) compile print str = "bar" >> Obviously "bar" remains the GDB-mmap()ed memory. > Maybe it would be best if GCC can report whether the compiled code exposes > address to its internal object outside - such as by such an assignment or by > passing such a pointer to some external function. I expect some scan of the > IR (intermediate representation - RTL/GIMPLE?) would be sufficient. There is some pointer escaping analysis that could be repurposed to that end in GCC. -Wreturn-local-addr is surely not enough to cover assigning gdb-compile pointers to inferior variables, but a new warning to cover more general pointer escaping to automatic variables might could be useful on its own, with a small extension for user expressions for it to apply to strings as well. However, it's not clear where to draw the line when a (pointer to a) string (literal) is passed to some inferior function. Technically, it is an escaping pointer, but printf won't save it, whereas add_to_list will. So we don't want it to be an error, at most a warning. But then, wouldn't we be better served by teaching users to use strdup in gdb-compile snippets when they wish to get strings preserved (and permanently leaked) in the inferior? Since we can't tell when it's ok for a pointer to escape in relatively common and harmless cases (the printf example above, any C++ function that takes a reference argument, C++ non-static member functions), I think even a warning would quickly become annoying due to the number of false positives. Using memory allocation primitives of the inferior might be cumbersome, but it will likely be learned fast, given how the failure to use them would break the inferior. -- Alexandre Oliva, freedom fighter http://FSFLA.org/~lxoliva/ You must be the change you wish to see in the world. -- Gandhi Be Free! -- http://FSFLA.org/ FSF Latin America board member Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer