Discussion:
Differences between debugger and native environment or execution?
(too old to reply)
Paul
2009-02-12 00:47:31 UTC
Permalink
Hi,

I have written a Win32 C++ program that uses a windowless richedit
control (ITextHost, ITextServices) to translate RTF to text. The
translations will occur in a service. I build the program in release
mode with optimizations turned off. When I run it within the debugger,
the program works fine. When I run the exact same binary outside of the
debugger, the program runs but the translations fail.

I would like to know what the debugger is doing to facilitate the RTF
translations. If I knew the difference I should be able to add the
missing steps to my app.

Thanks for your help.

Paul
Nathan Mates
2009-02-12 00:56:50 UTC
Permalink
Post by Paul
I have written a Win32 C++ program that uses a windowless richedit
control (ITextHost, ITextServices) to translate RTF to text. The
translations will occur in a service. I build the program in release
mode with optimizations turned off. When I run it within the debugger,
the program works fine. When I run the exact same binary outside of the
debugger, the program runs but the translations fail.
I've seen similar things before, where items launched by the
debugger (F5 key to run, with the VC++ keyboard shortcuts) works, and
items launched with Ctrl-F5 (run, not under debugger) failed. Pretty
much all of those turned out to be misuse of uninitialized memory.
Try ensuring that your class/struct constructors reset all member
variables, and that you deal with allocated memory correctly as well.

Nathan
--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein
Paul Lennon
2009-02-12 18:31:16 UTC
Permalink
Post by Nathan Mates
Post by Paul
I have written a Win32 C++ program that uses a windowless richedit
control (ITextHost, ITextServices) to translate RTF to text. The
translations will occur in a service. I build the program in release
mode with optimizations turned off. When I run it within the debugger,
the program works fine. When I run the exact same binary outside of the
debugger, the program runs but the translations fail.
I've seen similar things before, where items launched by the
debugger (F5 key to run, with the VC++ keyboard shortcuts) works, and
items launched with Ctrl-F5 (run, not under debugger) failed. Pretty
much all of those turned out to be misuse of uninitialized memory.
Try ensuring that your class/struct constructors reset all member
variables, and that you deal with allocated memory correctly as well.
Nathan
--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein
Thank you for the suggestion. I found the problem and it was me! I
revisited my RichEdit construction, removed some unnecessary variables
and found some key ones that were not set correctly.

The worst bugs to find are those in the code that you believe you wrote
correctly.

Paul
Nathan Mates
2009-02-12 18:43:18 UTC
Permalink
Post by Paul Lennon
Post by Nathan Mates
I've seen similar things before, where items launched by the
debugger (F5 key to run, with the VC++ keyboard shortcuts) works, and
items launched with Ctrl-F5 (run, not under debugger) failed. Pretty
much all of those turned out to be misuse of uninitialized memory.
Try ensuring that your class/struct constructors reset all member
variables, and that you deal with allocated memory correctly as well.
Thank you for the suggestion. I found the problem and it was me! I
revisited my RichEdit construction, removed some unnecessary variables
and found some key ones that were not set correctly.
That's what I thought. I wish that running under the debugger was
slightly more reliable in terms of misbehaving the same way as not
under the debugger. I've also been wanting an (optional, of course)
warning when all members of a class/struct aren't initialized by the
constructors. I've seen projects I'm on get bitten so many times when
a class has 15-odd member variables, and 4 constructors. Then, someone
adds member variable #16, and updates 1-3 of the constructors. Boom.
Occasionally. I want that to be a warning, and I'd upgrade that to an
error asap.

Nathan Mates
--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein
Paul
2009-02-16 00:12:46 UTC
Permalink
That's a great idea. Often I will write a defaults function that each
constructor will call when there are several constructors and assignment
operator. Your idea for the compiler to identify the problem would be
very useful. The compiler needn't verify that they are valid values,
just no unassigned. Perhaps someone from MS is listening.

Thanks for the help.
Paul
Post by Nathan Mates
Post by Paul Lennon
Post by Nathan Mates
I've seen similar things before, where items launched by the
debugger (F5 key to run, with the VC++ keyboard shortcuts) works, and
items launched with Ctrl-F5 (run, not under debugger) failed. Pretty
much all of those turned out to be misuse of uninitialized memory.
Try ensuring that your class/struct constructors reset all member
variables, and that you deal with allocated memory correctly as well.
Thank you for the suggestion. I found the problem and it was me! I
revisited my RichEdit construction, removed some unnecessary variables
and found some key ones that were not set correctly.
That's what I thought. I wish that running under the debugger was
slightly more reliable in terms of misbehaving the same way as not
under the debugger. I've also been wanting an (optional, of course)
warning when all members of a class/struct aren't initialized by the
constructors. I've seen projects I'm on get bitten so many times when
a class has 15-odd member variables, and 4 constructors. Then, someone
adds member variable #16, and updates 1-3 of the constructors. Boom.
Occasionally. I want that to be a warning, and I'd upgrade that to an
error asap.
Nathan Mates
--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein
Alex Blekhman
2009-02-12 08:44:38 UTC
Permalink
Post by Paul
I would like to know what the debugger is doing to facilitate
the RTF translations. If I knew the difference I should be able
to add the missing steps to my app.
I agree with Nathan. What you see is called Heisenbugs
(http://en.wikipedia.org/wiki/Heisenbug#Heisenbug). Look for
uninitialized memory/variables or race conditions (debugger
eliminates race conditions by altering thread timings).

Alex
Continue reading on narkive:
Loading...