This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Including <iostream> affects whether or not program freezes?
On Wed, Jul 9, 2008 at 5:49 PM, Chris Jefferson <chris@bubblescope.net> wrote:
>> 4. Compile with gcc 4.2.3 (Ubuntu 64 bit), with optimization: my
>> program freezes in a particular function
>>
>> Debugging this is difficult.
>
> While I could well be repeating what others say, my usual tools for
> situations like this, which (touch wood) tend to get me out of it:
>
> A) Turn on all warnings, and read what they say. I've found this kind
> of thing can be caused by a missing return statement.
No warnings...
> B) Turn on the debugging standard library, if you are using any of the
> STL in your code.
OK this reported a problem somewhere else, but fixing it didn't make
any difference to the freezing problem.
> C) Find the minimial set of optimisation flags you need to trigger
> your problem (in particular if you can turn off inlining it will make
> things easier). This makes the next stage easier.
At first it required -finline-functions, but then I manually inlined
an a function called in the part which freezes and now the minimum set
of flags that triggers the problem is:
-O1 -fstrict-aliasing
> D) Use valgrind and see what it comes up with.
Nothing at all.
A minimal version of the function which freezes is something like:
bool AIInterpreter::is_group_like_this(int n_side, int n_group) {
//it is the second condition (scanned_groups) which triggers this
code branch, but deleting anything at all here removes the bug
if ((!sides[n_side].groups[n_group].get_alive())
|| !sides[my_side].scanned_groups[n_side][n_group]
|| sides[n_side].groups[n_group].get_in_hangar()) {
while (l_iter != l_end)
++l_iter;
return false;
}
write_log(L"it never gets this far");
<the function continues but though deleting it removes the bug, the
fact the above log never gets written means it is probably irrelevant>
}
So I guess "while (l_iter != l_end)" is becoming an infinite loop, but
if I log the value of &(*l_iter) and &(*l_end) on each loop then a) it
removes the bug and b) there is nothing obviously wrong. Anything else
I can do?
James