0

I have the following code :-

void someFunc (someStruct* obj) {
    cout << obj->some_member;
}

someFunc is a call-back that I get from a library that I have no control over. If I compile this with gdbon=true then the resulting exec works exactly as it is supposed to do. On the other hand, if I compile it without the above flag, the exec segfaults. Opening up the core-dump in gdb shows that

obj=Variable "obj" is not available.

Any ideas on how I can narrow down the problem further (or what might possibly be wrong)?

EDIT:- Hey turns out this was a non-issue. There was an unsafe memory access much later in the code which in the release build (what with optimisations and all) appeared to gdb to be a problem in the above line of code. What's really surprising is that I tried to do this :-

void someFunc (someStruct* obj) {
    if (obj==NULL) return;
    cout<<"here1\n";
    cout<<obj->some_member;
    cout<<"here2\n"
}

And this would randomly result in

here1

sometimes and

here1
here2

some other times. Which kinda confused me a bit again... But the problem was elsewhere...

owagh
  • 3,428
  • 2
  • 31
  • 53
  • I found this excellent question a couple of moments after posting my own. Doesn't seem to help however. http://stackoverflow.com/questions/1762088/common-reasons-for-bugs-in-release-version-not-present-in-debug-mode – owagh Mar 01 '12 at 16:47
  • Try printing out the value of obj. i.e. cout << obj. – akhisp Mar 01 '12 at 16:49

1 Answers1

1

try running under valgrind, that should give you some clues

Chris Card
  • 3,216
  • 20
  • 15