Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
To: "Chun, Eric Y" <eric.y.chun@intel.com>
Cc: "gdb@sourceware.org" <gdb@sourceware.org>
Subject: Re: Conditional Breakpoints with Pointers
Date: Mon, 04 May 2015 21:48:00 -0000	[thread overview]
Message-ID: <1430776102.2159.2.camel@soleil> (raw)
In-Reply-To: <64E3233B30622847B1E5ED56D2C1DBF00CACDC9F@FMSMSX108.amr.corp.intel.com>

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 <iostream>
>     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


      reply	other threads:[~2015-05-04 21:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-04 21:12 Chun, Eric Y
2015-05-04 21:48 ` Philippe Waroquiers [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1430776102.2159.2.camel@soleil \
    --to=philippe.waroquiers@skynet.be \
    --cc=eric.y.chun@intel.com \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox