J
jacob navia
I have trouble debugging C++. For instance, I learned recently that code
that compiled with gcc -Wall without a single warning can be completely
buggy.
The reason is that the C++ standard says that using a pointer of another
type to change memory as the type declared that this memory should be
is "undefined"...
Well, gcc has an option (that I discovered later)
-Wstrict-aliasing
that should warn you if you are doing something wrong. Since that
warning is enabled when -Wall is used, I thought we were protected,
and filed a bug report when we discovered that gcc generated code that
reads a value from uninitialized memory.
Of course, we wanted to make things easy to the gcc folks, and
wasted a lot of time isolating the bug, and then we sent it
to gcc's bug database.
The answer was simply
"Your code has aliasing problems. This is not the place to
educate you about C/C++"
We forgot to pass the code snippet through -Wall and the gcc folks
apparently did not understand that this snippet wasn't the problem
Great.
But how come that gcc doesn't emit the slightest warning?
Well, we discovered that -Wall does enable the -Wstrict-aliasing but
that option has a "scale" i.e. you can say
-Wstrict-aliasing=1
up to
-Wstrict-aliasing=5
When you set -Wall you enable -Wstrict-aliasing=3.
OK. We increased the level to 5 (lengthening the compile time of our
software that is already a staggering 20 minutes in a 4 core machine)
Still, gcc doesn't emit A SINGLE WARNING!
Now, how can we discover this?
The problem is that this code was written well before the new C++
standard was written. It was written in a time when doing this was
correct (In 32 bit pointers)
struct twoPointers {
void *a;
void *b;
};
And you could manipulate that data as it would be a single 64 bit
integer.
Since we do NOT rewrite all our software every time the C++ standard
changes, how can we find this kind of bugs?
I thought there could be a book with *advanced* C++ debugging but a
Google search, then an Amazon search yielded nothing
but books for beginners or user manuals of Visual C++ debugger
written in a book form.
Is there a combination of gcc warnings (that is NOT included in Wall
since we already have that) that could be useful here?
Is there a tool somewhere that could diagnose this problem?
And last but not least: Is there a good book in C++ debugging?
Thanks in advance
jacob navia
that compiled with gcc -Wall without a single warning can be completely
buggy.
The reason is that the C++ standard says that using a pointer of another
type to change memory as the type declared that this memory should be
is "undefined"...
Well, gcc has an option (that I discovered later)
-Wstrict-aliasing
that should warn you if you are doing something wrong. Since that
warning is enabled when -Wall is used, I thought we were protected,
and filed a bug report when we discovered that gcc generated code that
reads a value from uninitialized memory.
Of course, we wanted to make things easy to the gcc folks, and
wasted a lot of time isolating the bug, and then we sent it
to gcc's bug database.
The answer was simply
"Your code has aliasing problems. This is not the place to
educate you about C/C++"
We forgot to pass the code snippet through -Wall and the gcc folks
apparently did not understand that this snippet wasn't the problem
Great.
But how come that gcc doesn't emit the slightest warning?
Well, we discovered that -Wall does enable the -Wstrict-aliasing but
that option has a "scale" i.e. you can say
-Wstrict-aliasing=1
up to
-Wstrict-aliasing=5
When you set -Wall you enable -Wstrict-aliasing=3.
OK. We increased the level to 5 (lengthening the compile time of our
software that is already a staggering 20 minutes in a 4 core machine)
Still, gcc doesn't emit A SINGLE WARNING!
Now, how can we discover this?
The problem is that this code was written well before the new C++
standard was written. It was written in a time when doing this was
correct (In 32 bit pointers)
struct twoPointers {
void *a;
void *b;
};
And you could manipulate that data as it would be a single 64 bit
integer.
Since we do NOT rewrite all our software every time the C++ standard
changes, how can we find this kind of bugs?
I thought there could be a book with *advanced* C++ debugging but a
Google search, then an Amazon search yielded nothing
but books for beginners or user manuals of Visual C++ debugger
written in a book form.
Is there a combination of gcc warnings (that is NOT included in Wall
since we already have that) that could be useful here?
Is there a tool somewhere that could diagnose this problem?
And last but not least: Is there a good book in C++ debugging?
Thanks in advance
jacob navia