From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 36183 invoked by alias); 4 May 2015 21:48:23 -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 36173 invoked by uid 89); 4 May 2015 21:48:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mailrelay114.isp.belgacom.be Received: from mailrelay114.isp.belgacom.be (HELO mailrelay114.isp.belgacom.be) (195.238.20.141) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 04 May 2015 21:48:20 +0000 X-Belgacom-Dynamic: yes X-Cloudmark-SP-Filtered: true X-Cloudmark-SP-Result: v=1.1 cv=b5VF44rymZs9Y1DiFqPAMix8rWtyBsB+bu/OWkEeo3k= c=1 sm=2 a=IkcTkHD0fZMA:10 a=PEjT_a2EmoFMkr7f5gIA:9 a=QEXdDO2ut3YA:10 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CWAQDt50dV/7LMgG0NT4dYyjICgW4QAQEBAQEBAYUrAQEEI1YQCxgCAiYCAlcGiEOyF3CTXAEBAQEBAQEDAQEBAQEBHIEhihiFBQeCaIFFAQSeA4ZEjjaEGYMyAQEB Received: from 178.204-128-109.adsl-dyn.isp.belgacom.be (HELO [192.168.1.15]) ([109.128.204.178]) by relay.skynet.be with ESMTP; 04 May 2015 23:48:17 +0200 Subject: Re: Conditional Breakpoints with Pointers From: Philippe Waroquiers To: "Chun, Eric Y" Cc: "gdb@sourceware.org" In-Reply-To: <64E3233B30622847B1E5ED56D2C1DBF00CACDC9F@FMSMSX108.amr.corp.intel.com> References: <64E3233B30622847B1E5ED56D2C1DBF00CACDC9F@FMSMSX108.amr.corp.intel.com> Content-Type: text/plain; charset="UTF-8" Date: Mon, 04 May 2015 21:48:00 -0000 Message-ID: <1430776102.2159.2.camel@soleil> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2015-05/txt/msg00006.txt.bz2 On Mon, 2015-05-04 at 21:12 +0000, Chun, Eric Y wrote: > in gdb, how do i set a conditional breakpoint depending on value of pointer keeping in mind that i have to check if pointer is null before dereferencing pointer? > > here is an example of code i'm trying to debug: > #include > using namespace std; > > int main () { > int *i[10]; > int *j = NULL; > int k; > > i[4] = new int; > *i[4] = 8; > > for (k=0; k < 10; k++) { > j = i[k]; > } > > return 0; > } > > i set conditional breakpoint at line "j=i[k]" but i got a seg fault: > (gdb) b 14 if j && *j == 8 > (gdb) r > Starting program: /nfs/blahblah/a.out > Failed to read a valid object file image from memory. > Program received signal SIGSEGV, Segmentation fault. > > does anybody know why there is a segfault? You only initialises i[4]. So, the rest of i array has random values pointing to nowhere, they are not necessarily NULL. Use valgrind to search such errors, not gdb :). Philippe