Discussion:
StackWalk64 makes x64 app unable to unwind
(too old to reply)
Kevin8237
2010-04-28 04:51:01 UTC
Permalink
Raw Message
Hello,

I think I'm losing it...this all works just fine in x86, but not in x64.

I have a C++/CLI code that essentially calls _controlfp_s, catches SEH
exceptions (exceptions thrown from Intel Fortran .dll file loaded via
LibraryLoad), and builds a call stack. So far so good.

However, if the StackWalk64 call gets to a frame that involves my C++/CLI
.dll file, then I get problems.

If I use the _set_se_translator / throw method, then somewhere between
throw and catch, something decides to call abort().

If I use the __try/__except(Filter that calls StackWalk64 and returns 1)
method, then I get the NT_STATUS_BAD_STACK MessageBox error from Visual
Studio.

Even the Visual Studio debugger "Call Stack" window looks wrong. If I
double-click into the function that caused the exception, the arguments
inside that function are just bogus.

All this only on x64, and only if StackWalk64 makes it into a frame that
belongs to my C++/CLI .dll.

I've tried VS2008. I've tried VS2010. I've tried the VS2010 dbghelp
library. I've tried the Feb 2010 dbghelp library.

Ideas?
Jochen Kalmbach [MVP]
2010-04-28 05:46:02 UTC
Permalink
Raw Message
Hi Kevin8237!
Post by Kevin8237
I think I'm losing it...this all works just fine in x86, but not in x64.
Waht does you mean?
Your programm ist compiled as x64 or still as x86, but running on x64
(x86 on x64)?
Post by Kevin8237
However, if the StackWalk64 call gets to a frame that involves my C++/CLI
..dll file, then I get problems.
StackWalk only works correctly for native stack-frames.

WHY dou you want to walk the callstack?
--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Kevin8237
2010-04-28 07:27:02 UTC
Permalink
Raw Message
Hello,
Post by Jochen Kalmbach [MVP]
Hi Kevin8237!
Post by Kevin8237
I think I'm losing it...this all works just fine in x86, but not in x64.
Waht does you mean?
Your programm ist compiled as x64 or still as x86, but running on x64
(x86 on x64)?
I compile and ship both a x86 version and a x64 version. x64 is
preferrable, and x86 is "fallback" depending on user's operating system.
Post by Jochen Kalmbach [MVP]
Post by Kevin8237
However, if the StackWalk64 call gets to a frame that involves my C++/CLI
..dll file, then I get problems.
StackWalk only works correctly for native stack-frames.
WHY dou you want to walk the callstack?
I need the stack trace to help the user. Typically if user enters invalid
input, it will cause a divide-by-zero crash (or similar) somewhere in the
Fortran (native!) code. Once the native code exception is handled properly
(as is the case for the x86 build), I don't have a problem.
Post by Jochen Kalmbach [MVP]
--
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/
.
Trey Nash
2010-05-04 22:23:39 UTC
Permalink
Raw Message
Hi Kevin,

Stack walking on x64 has "evolved" over time so to speak. By that I mean it
has gotten better and better with each OS release.

To effectively walk stacks on x64, you must set the DisablePagingExecutive
registry value. You could do that with the following:

REG ADD "HKLM\System\CurrentControlSet\Control\Session Manager\Memory
Management" -v DisablePagingExecutive -d 0x1 -t REG_DWORD -f

BTW, I have authored a forthcoming blog post for our team blog
(http://blogs.msdn.com/ntdebugging) that talks more about stack walking in
x64 and the unwind metadata necessary for one to effectively do so.

I hope this helps,

-Trey
Post by Kevin8237
Hello,
Post by Jochen Kalmbach [MVP]
Hi Kevin8237!
Post by Kevin8237
I think I'm losing it...this all works just fine in x86, but not in x64.
Waht does you mean?
Your programm ist compiled as x64 or still as x86, but running on x64
(x86 on x64)?
I compile and ship both a x86 version and a x64 version. x64 is
preferrable, and x86 is "fallback" depending on user's operating system.
Post by Jochen Kalmbach [MVP]
Post by Kevin8237
However, if the StackWalk64 call gets to a frame that involves my C++/CLI
..dll file, then I get problems.
StackWalk only works correctly for native stack-frames.
WHY dou you want to walk the callstack?
I need the stack trace to help the user. Typically if user enters invalid
input, it will cause a divide-by-zero crash (or similar) somewhere in the
Fortran (native!) code. Once the native code exception is handled properly
(as is the case for the x86 build), I don't have a problem.
Post by Jochen Kalmbach [MVP]
--
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/
.
Sa Li
2011-08-06 17:11:08 UTC
Permalink
Raw Message
might a little away from your topic.

I found from msdn that _controlfp is not supported on x64 platform, which will give invalid-parameter exceptions:(

refer to below link:

http://msdn.microsoft.com/en-us/library/e9b52ceh%28v=VS.90%29.aspx

"On the x64 architecture, changing the floating point precision is not supported. If the precision control mask is used on that platform, an assertion and the invalid parameter handler is invoked, as described in Parameter Validation."

have you ever found any solution to use _controlfp on x64 platform?
Post by Kevin8237
Hello,
I think I am losing it...this all works just fine in x86, but not in x64.
I have a C++/CLI code that essentially calls _controlfp_s, catches SEH
exceptions (exceptions thrown from Intel Fortran .dll file loaded via
LibraryLoad), and builds a call stack. So far so good.
However, if the StackWalk64 call gets to a frame that involves my C++/CLI
.dll file, then I get problems.
If I use the _set_se_translator / throw method, then somewhere between
throw and catch, something decides to call abort().
If I use the __try/__except(Filter that calls StackWalk64 and returns 1)
method, then I get the NT_STATUS_BAD_STACK MessageBox error from Visual
Studio.
Even the Visual Studio debugger "Call Stack" window looks wrong. If I
double-click into the function that caused the exception, the arguments
inside that function are just bogus.
All this only on x64, and only if StackWalk64 makes it into a frame that
belongs to my C++/CLI .dll.
I have tried VS2008. I have tried VS2010. I have tried the VS2010 dbghelp
library. I have tried the Feb 2010 dbghelp library.
Ideas?
Post by Jochen Kalmbach [MVP]
Hi Kevin8237!
Waht does you mean?
Your programm ist compiled as x64 or still as x86, but running on x64
(x86 on x64)?
StackWalk only works correctly for native stack-frames.
WHY dou you want to walk the callstack?
--
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Post by Kevin8237
Hello,
I compile and ship both a x86 version and a x64 version. x64 is
preferrable, and x86 is "fallback" depending on user's operating system.
I need the stack trace to help the user. Typically if user enters invalid
input, it will cause a divide-by-zero crash (or similar) somewhere in the
Fortran (native!) code. Once the native code exception is handled properly
(as is the case for the x86 build), I do not have a problem.
Post by Trey Nash
Hi Kevin,
Stack walking on x64 has "evolved" over time so to speak. By that I mean it
has gotten better and better with each OS release.
To effectively walk stacks on x64, you must set the DisablePagingExecutive
REG ADD "HKLM\System\CurrentControlSet\Control\Session Manager\Memory
Management" -v DisablePagingExecutive -d 0x1 -t REG_DWORD -f
BTW, I have authored a forthcoming blog post for our team blog
(http://blogs.msdn.com/ntdebugging) that talks more about stack walking in
x64 and the unwind metadata necessary for one to effectively do so.
I hope this helps,
-Trey
Loading...