From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14975 invoked by alias); 2 Sep 2005 09:57:12 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 14935 invoked by uid 22791); 2 Sep 2005 09:57:02 -0000 Received: from main.gmane.org (HELO ciao.gmane.org) (80.91.229.2) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Fri, 02 Sep 2005 09:57:02 +0000 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1EB8Gb-0002Pj-Mi for gdb@sources.redhat.com; Fri, 02 Sep 2005 11:55:25 +0200 Received: from zigzag.lvk.cs.msu.su ([158.250.17.23]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 02 Sep 2005 11:55:25 +0200 Received: from ghost by zigzag.lvk.cs.msu.su with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 02 Sep 2005 11:55:25 +0200 To: gdb@sources.redhat.com From: Vladimir Prus Subject: Re: "info locals" -- is variable initialized Date: Fri, 02 Sep 2005 09:57:00 -0000 Message-ID: References: <1125653235.9801.18.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit User-Agent: KNode/0.8.2 X-SW-Source: 2005-09/txt/msg00012.txt.bz2 Ramana Radhakrishnan wrote: > >> >> When entering this function, KDevelop asks gdb via "info locals" what >> locals vars are there. But, gdb reports all variables, even though at the >> function entry 'i2' is not initialized (or, from C++ point of view, not >> even visible yet). For pretty priting 'i2', I have to evaluate >> 'i2.prettyURL(0)', which will just crash. I can use "set unwindonsignal >> on", but generally, calling methods on uninitialized object can damage >> random memory. > > GDB puts a breakpoint after the prologue of a function. Which means that > all locals in scope have been created / allocated space for . Hence you > would see i2 , right ? Wrong, I think. Function progolue only allocates space for KURL, but does not call the constructor. Consider: int main() { int i = 10; std::vector v2; KURL url = "http://boost.org"; } And assembler of it: 0x080487f4 : push %ebp 0x080487f5 : mov %esp,%ebp 0x080487f7 : push %ebx 0x080487f8 : sub $0x84,%esp 0x080487fe : and $0xfffffff0,%esp 0x08048801 : mov $0x0,%eax 0x08048806 : sub %eax,%esp 0x08048808 : movl $0xa,0xfffffff4(%ebp) 0x0804880f : lea 0xffffffc8(%ebp),%eax 0x08048812 : mov %eax,(%esp) 0x08048815 : call 0x8048924 0x0804881a : lea 0xffffffc8(%ebp),%eax 0x0804881d : mov %eax,0x4(%esp) 0x08048821 : lea 0xffffffd8(%ebp),%eax 0x08048824 : mov %eax,(%esp) 0x08048827 : call 0x80489a0 ........... and only here std::vector is initialized. So, there's a window there variable does not exists according to C++, but exists according to gdb. - Volodya