This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Conditional Breakpoints with Pointers
- From: Philippe Waroquiers <philippe dot waroquiers at skynet dot be>
- To: "Chun, Eric Y" <eric dot y dot chun at intel dot com>
- Cc: "gdb at sourceware dot org" <gdb at sourceware dot org>
- Date: Mon, 04 May 2015 23:48:22 +0200
- Subject: Re: Conditional Breakpoints with Pointers
- Authentication-results: sourceware.org; auth=none
- References: <64E3233B30622847B1E5ED56D2C1DBF00CACDC9F at FMSMSX108 dot amr dot corp dot intel dot 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