Hello everyone,


I asked question about debugging native code before -- mode details it is
about optimized release mode x64 code which will use register to store
variable which will block debugger from monitoring the variable value.

Today, I debugged a managed program, also in release build for the managed
program, but I do not compile it with x64, and it is for "Any CPU". I met
with the same issue and when see the assembly code, it has the same pattern
that putting some variable in register prevents debugger to see its value.

My question is, I am not 100% confident enough (since the build is not for
x64 release, but for "Any CPU" release, different build option from the
native code issue before) and I want to confirm with you the same issue
happens not only in native code in x64 release mode, but also in managed code
in release "Any CPU" mode?


thanks in advance,
George

Re: debugging release version build issue in managed code by Carl

Carl
Sun Oct 05 09:37:21 CDT 2008

George wrote:
> Hello everyone,
>
>
> I asked question about debugging native code before -- mode details
> it is about optimized release mode x64 code which will use register
> to store variable which will block debugger from monitoring the
> variable value.
>
> Today, I debugged a managed program, also in release build for the
> managed program, but I do not compile it with x64, and it is for "Any
> CPU". I met with the same issue and when see the assembly code, it
> has the same pattern that putting some variable in register prevents
> debugger to see its value.
>
> My question is, I am not 100% confident enough (since the build is
> not for x64 release, but for "Any CPU" release, different build
> option from the native code issue before) and I want to confirm with
> you the same issue happens not only in native code in x64 release
> mode, but also in managed code in release "Any CPU" mode?

It occurs for every target - release builds may store variables temporarily
(or permanently) in registers and the variable may even move from register
to register over time or not exist at all at some points. This is one of
the main reasons that a "debug" build existss.

When you compile managed code for "Any CPU", the runtime chooses the CPU
target. Of course, the target will always be x86 if the code is run on a
32-bit machine, but when run on a 64-bit machine "Any CPU" code will only
run as 32-bit code if it's loaded into an already running 32-bit process.
In all other cases it will run as 64-bit code.

-cd



Re: debugging release version build issue in managed code by George

George
Mon Oct 06 00:55:00 CDT 2008

Thanks cd,


Actually I build it with Any CPU when build the managed code, and I run it
on x64 machine. I noticed fast call calling convention is used -- it is from
the assembly code which the 1st 4 parameters are in register. So I suspect,
for managed code even if I build it with Any CPU release mode, but if I run
it on x64 machine, it becomes a x64 native code release mode, and follows x64
release mode assembly code rules to optimize (when I run it on x86 machine,
it becomes a x86 native code release mode, and follows x86 release mode
assembly code rules to optimize) -- so it is why I met with the similar issue
that debugger can not display variable values when variable is in register.
So, even if managed code from IL level are the same, the resulting native
assembly code is different on x64/x86. And it is also called JIT platform
dependent optimization?

Do you think my analysis is correct? :-)


regards,
George

Re: debugging release version build issue in managed code by Ondrej

Ondrej
Thu Oct 16 03:39:32 CDT 2008

Please, learn something about how manager works first. Basics are:

With managed code there are two compilations: compile time (into
intermediate representation, which is the same for all platforms) and
runtime (this intermediate representation is JIT compiled into native code).

> assembly code rules to optimize) -- so it is why I met with the
similar issue
> that debugger can not display variable values when variable is in
register.

The intermediate code is a virtual machine code, therefore you can
handle it with the same approach as you do for the native code, and this
is also what compiler does - it uses the same optimization techniques
(variables in registers). See my recent answer in your original "native
release debugging" topic to see why you see the issue and what
techniques you can learn to be able to watch variables in the release build.

Cheers
Ondrej

George napsal(a):
> Thanks cd,
>
>
> Actually I build it with Any CPU when build the managed code, and I run it
> on x64 machine. I noticed fast call calling convention is used -- it is from
> the assembly code which the 1st 4 parameters are in register. So I suspect,
> for managed code even if I build it with Any CPU release mode, but if I run
> it on x64 machine, it becomes a x64 native code release mode, and follows x64
> release mode assembly code rules to optimize (when I run it on x86 machine,
> it becomes a x86 native code release mode, and follows x86 release mode
> assembly code rules to optimize) -- so it is why I met with the similar issue
> that debugger can not display variable values when variable is in register.
> So, even if managed code from IL level are the same, the resulting native
> assembly code is different on x64/x86. And it is also called JIT platform
> dependent optimization?
>
> Do you think my analysis is correct? :-)
>
>
> regards,
> George

Re: debugging release version build issue in managed code by George

George
Thu Oct 16 07:58:47 CDT 2008

Thanks Ondrej,


I am satisfied with your answered. :-)


regards and have a good day,
George