GetThreadStackTrace returns nothing - Delphi XE3/XE5 64bit
GetThreadStackTrace returns nothing - Delphi XE3/XE5 64bit
Hi,
I have madCollection 4.0.8.1 installed.
Delphi XE3 or XE5 - one form VCL forms application.
madExcept.GetThreadStackTrace(); returns empty string if compiler target platform is Windows 64 bit
and returns proper stack trace if compiler target platform is Windows 32 bit
procedure TForm1.Button1Click(Sender: TObject);
begin
Vcl.Dialogs.ShowMessage(madExcept.GetThreadStackTrace());
end;
Please advise on the issue.
Thank you,
Pavel
I have madCollection 4.0.8.1 installed.
Delphi XE3 or XE5 - one form VCL forms application.
madExcept.GetThreadStackTrace(); returns empty string if compiler target platform is Windows 64 bit
and returns proper stack trace if compiler target platform is Windows 32 bit
procedure TForm1.Button1Click(Sender: TObject);
begin
Vcl.Dialogs.ShowMessage(madExcept.GetThreadStackTrace());
end;
Please advise on the issue.
Thank you,
Pavel
Re: GetThreadStackTrace returns nothing - Delphi XE3/XE5 64b
I've double and triple checked my code, changed a few things, but the underlying API (StackWalk64) doesn't seem to work right. I'm not sure why. From what I can see, I'm calling it correctly.
A google search seems to recommend raising a dummy exception to do a stack trace for the current thread. That seems to work nicely:
Ugly, but I don't have a better solution at the moment.
A google search seems to recommend raising a dummy exception to do a stack trace for the current thread. That seems to work nicely:
Code: Select all
function GetThreadStackTrace_Hacked() : UnicodeString;
begin
try
integer(nil^) := 0;
except
result := GetCrashStackTrace();
end;
end;
Re: GetThreadStackTrace returns nothing - Delphi XE3/XE5 64b
Thank you for the quick answer - we will use recommended hack for now.
Also I am not sure, but should Wow64GetThreadContext be used for win64 instead of GetThreadContext in GetThreadInfos (madexcept.pas)?
Thank you,
Pavel
Also I am not sure, but should Wow64GetThreadContext be used for win64 instead of GetThreadContext in GetThreadInfos (madexcept.pas)?
Thank you,
Pavel
Re: GetThreadStackTrace returns nothing - Delphi XE3/XE5 64b
The information returned by GetThreadContext() is not actually used for the x64 stack trace. Actually for the stack trace I'm using RtlCaptureContext(), which is the recommended method to initialize the context for x64 stack walking.
Re: GetThreadStackTrace returns nothing - Delphi XE3/XE5 64b
> but I don't have a better solution at the moment.
I wonder if anything has improved in the past 4 years regarding this issue?
Otherwise it could make sense to at least add the workaround to MadExcept.
I wonder if anything has improved in the past 4 years regarding this issue?
Otherwise it could make sense to at least add the workaround to MadExcept.
Re: GetThreadStackTrace returns nothing - Delphi XE3/XE5 64b
I haven't tested if the problem is gone in newer OSs or not. If not, the workaround should still work. I'm not eager to add the workaround to madExcept because if I do, even if the underlying problem gets fixed in a future OS version, the dummy exception would always stay in madExcept.
Re: GetThreadStackTrace returns nothing - Delphi XE3/XE5 64b
> I'm not eager to add the workaround to madExcept
So you think it is better if many of your customers run into that issue, spend time in analyzing the issue and seeking a workaround, and then all copy this workaround to their projects?
> the dummy exception would always stay in madExcept.
It should be fairly easy to use it only below a certain Windows build number.
So you think it is better if many of your customers run into that issue, spend time in analyzing the issue and seeking a workaround, and then all copy this workaround to their projects?
> the dummy exception would always stay in madExcept.
It should be fairly easy to use it only below a certain Windows build number.
Re: GetThreadStackTrace returns nothing - Delphi XE3/XE5 64b
I've just retested it with Tokyo 10.2 Update 1 - it does not work (still returns empty stack trace).
for years we use workaround:
Thank you,
Pavel
for years we use workaround:
Code: Select all
function GetStackTrace: string;
// Re: GetThreadStackTrace returns nothing - Delphi XE3/XE5 64b
// http://forum.madshi.net/viewtopic.php?f=4&t=27637&p=46729#p46729
// Unread postby madshi » Thu Oct 31, 2013 7:49 pm
// I've double and triple checked my code, changed a few things, but the underlying API (StackWalk64) doesn't seem to work right. I'm not sure why. From what I can see, I'm calling it correctly.
// A google search seems to recommend raising a dummy exception to do a stack trace for the current thread. That seems to work nicely:
function _GetThreadStackTrace_Hacked: UnicodeString;
var
vPos: integer;
begin
try
Abort;
except
Result := madExcept.GetCrashStackTrace;
// remove part of the stack generated by this call
vPos := pos('GetStackTrace', Result);
if vPos <> -1 then
Result := copy(Result, vPos + 14);
end;
end;
begin
// in case of exception need a crash stack - otherwise just current stack
if ExceptAddr <> nil then
Result := madExcept.GetCrashStackTrace
else
Result := _GetThreadStackTrace_Hacked;
end;
Pavel
Re: GetThreadStackTrace returns nothing - Delphi XE3/XE5 64b
you have to suspend the thread to get it to work.
Re: GetThreadStackTrace returns nothing - Delphi XE3/XE5 64b
This thread is about getting the callstack of the current thread. If you suspend your own thread, you're dead.