AAAAAHHHH!! Locals getting trampled (windbg problem?)

Hi,

I am using WindBg to debug my driver and I have been seeing some
unexpected behavior. Sometimes when I step into a function, one or more
of the local variables aren’t displayed in the “Locals” window. I tried
bringing up their value in the “Watch” window, but I usually get “Error
: Cannot get value”. My only guess is that they are being optimized
out. But I am building a checked build, I assumed that all
optimizations would be off.

Normally I wouldn’t write about something like this, I’d just put in
some debug statements and bow before my Microsoft shrine and thank it
that I have debug statements. But I’ve noticed that some of my local
variables get assigned the same address as the arguments for the
function they are in. As soon as one of my locals gets assigned a
value, the function argument gets set to that value, too! I’ll have a
seemingly innocuous statement like j = 0; and 3 out of my 5 locals get
set to zero.

My Help | About says I am using Microsoft WinDbg:2.0.0023.0 Version 5.0
(Build 2195: Service Pack 1).

Can you please give me a suggestion for a solution?

Thanks
John


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

John,

I don’t know about the issue with your locals getting trashed, but
the KB article below could be your problem with your “debug” builds
still creating optimized code. The “October 2000” MSDN CD version of
the DDK still has this problem. It gave me a few headaches until I
was filled in on the issue (thanks to Peter @ OSR) and corrected it.

  • Jay


Jay Talbott
Staff Software Engineer
Motorola Computer Group
2900 S. Diablo Way
DW220
Tempe, AZ 85282
(602) 438-3481
xxxxx@mcg.mot.com

Article ID: Q263979

PRB: Checked Build Environment of WinHEC 2000 DDK


The information in this article applies to:

Microsoft Windows 2000 Driver Development Kit (DDK)


SYMPTOMS
When you build the checked version of a device driver by using the
WinHEC release of the Windows 2000 DDK, compiler optimizations are
turned on by default. This may result in difficulties while you debug
the driver.

RESOLUTION
A small change needs to be made to the %BASEDIR%\bin\Setenv.bat file
to correct this problem. The changes are as follows (in bold):

:checked
rem set up an NT checked build environment

set BUILD_ALT_DIR=chk
set NTDBGFILES=1
set NTDEBUG=ntsd
set NTDEBUGTYPE=windbg
set MSC_OPTIMIZATION=/Od /Oi [the /Od /Oi is in bold]

Additional query words:

Keywords : kbKMode kbOSWin2000 kbOSWin2000bug kbDSupport
Issue type : kbprb
Technology :

John Hirschi wrote:

Hi,

I am using WindBg to debug my driver and I have been seeing some
unexpected behavior. Sometimes when I step into a function, one
or more of the local variables aren’t displayed in the “Locals”
window. I tried bringing up their value in the “Watch” window,
but I usually get “Error : Cannot get value”. My only guess is
that they are being optimized out. But I am building a checked
build, I assumed that all optimizations would be off.

Normally I wouldn’t write about something like this, I’d just put
in some debug statements and bow before my Microsoft shrine and
thank it that I have debug statements. But I’ve noticed that some
of my local variables get assigned the same address as the arguments
for the function they are in. As soon as one of my locals gets
assigned a value, the function argument gets set to that value,
too! I’ll have a seemingly innocuous statement like j = 0; and 3
out of my 5 locals get set to zero.

My Help | About says I am using Microsoft WinDbg:2.0.0023.0 Version
5.0 (Build 2195: Service Pack 1).

Can you please give me a suggestion for a solution?

Thanks
John


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

A free build, with full optimization, implies /Oi by default. If you
do a free build and look in buildfre.log for what optimization flags
are specified by default, you find /Oxs /Oy. The VC++ docs for the
/Ox states that is equivalent to /Ob1 /Og /Oi /Ot /Oy /Gs. So a free
build already always has /Oi, and thus does not need to be added to
the DDK setenv.bat file. The /Os specifies favoring size over speed,
counteracting the /Ot implied by /Ox.

The problem with the checked build was that the lack of any
optimization flags in the setenv.bat file results in full
optimization, just like a free build. The fix provided in the
knowledge base article I mentioned before resolves the problem.
With a fixed checked build environment, the compiler optimization
flags are /Od /Oi /Oy-.

The /Oy- added in a checked build, and /Oy added in a free build
always override any user specified optimizations to make sure that
frame pointers are always created on the call stack for checked
builds for debugging purposes, and are NOT created on free builds
for faster performance. These seem to always be tacked on the end
of the default and/or specified optimization flags.

  • Jay


Jay Talbott
Staff Software Engineer
Motorola Computer Group
2900 S. Diablo Way
DW220
Tempe, AZ 85282
(602) 438-3481
xxxxx@mcg.mot.com

“Barila, Phil” wrote:

/Oi is an optimization. If you specify /Od without it, you will get
absolutely no optimization. Not sure why MS defined /Oi in the Checked
build, but not the Free build, unless they were intending that the default
optimization in the Free build favor code size over speed. If I am reading
the MSDN library entry correctly, you only get intrinsics that you define in
the #pragma, so if you /Oi, but don’t define the intrinsic, you don’t get
the inlined instructions. So the effect is the same as /Od only. Anyone
know if I read the doc right?

Yes, *if* you use intrinsics, you must have /Oi, or you will build faulty
images. I discovered this by accident, when I took over development of
something that someone else had started, which used several intrinsics. If
you define the intrinsic, but don’t specify /Oi, you get confusing crashes.
You won’t get linker errors, you won’t get compile errors, just the crashes.

And yes, I think the default should be to have /Oi set in both build
environments, but I was bit quite painfully by its absence. Since it
appears that those of us who use defined intrinsics are a small minority of
DDK users, it’s probably a no-op for most people. Absolutely necessary for
those of us who need it, though.

Phil

-----Original Message-----
From: Nate Bushman [mailto:xxxxx@Legato.com]
Sent: Thursday, March 01, 2001 4:17 PM
To: NT Developers Interest List
Subject: [ntdev] Re: AAAAAHHHH!! Locals getting trampled (windbg prob
lem?)

I’m a bit confused. First, the KB article that Jay Talbott
mentions says that (if I understand this correctly) you can
turn off the default optimization in a checked build by
modifying %BASEDIR%\bin\Setenv.bat so that it does this…
set MSC_OPTIMIZATION=/Od /Oi

Why wouldn’t “set MSC_OPTIMIZATION=/Od” be sufficient? The
MSDN docs say that /Od will disable ALL optimizations. Wouldn’t
this include the /Oi optimization?

>From the rest of the posts, am I right in stating that W2K free
builds will generate faulty images if you use intrinsic functions
in your code? Is the solution to this to add the following
line to your SOURCES file:
MSC_OPTIMIZATION=/Oi
Or should you edit setenv.bat to set this environment variable?

If this bug is for real, it seems that everyone should be using
/Oi for their free builds to ensure that they don’t end up building
faulty images.


You are currently subscribed to ntdev as: xxxxx@mcg.mot.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com