delphi - DUnit2 的 CallerAddr 函数有什么作用?如何将其转换为 64 位?

标签 delphi assembly 32bit-64bit

我试图让 DUnit2 在 64 位下工作,但我对这个方法的作用感到困惑,更不用说如何将其转换为 64 位了。纯 Pascal 会更好,但由于它引用堆栈(ebp),因此可能不可能。

function CallerAddr: Pointer; assembler;
const
  CallerIP = $4;
asm
   mov   eax, ebp
   call  IsBadPointer
   test  eax,eax
   jne   @@Error

   mov   eax, [ebp].CallerIP
   sub   eax, 5   // 5 bytes for call

   push  eax
   call  IsBadPointer
   test  eax,eax
   pop   eax
   je    @@Finish

@@Error:
   xor eax, eax
@@Finish:
end;

最佳答案

function RtlCaptureStackBackTrace(FramesToSkip: ULONG; FramesToCapture: ULONG; 
  out BackTrace: Pointer; BackTraceHash: PULONG): USHORT; stdcall; 
  external 'kernel32.dll' name 'RtlCaptureStackBackTrace' delayed;

function CallerAddr: Pointer;
begin
  // Skip 2 Frames, one for the return of CallerAddr and one for the
  // return of RtlCaptureStackBackTrace
  if RtlCaptureStackBackTrace(2, 1, Result, nil) > 0 then
  begin
    if not IsBadPointer(Result) then
      Result := Pointer(NativeInt(Result) - 5)
    else
      Result := nil;
  end
  else
  begin
    Result := nil;
  end;
end;

关于delphi - DUnit2 的 CallerAddr 函数有什么作用?如何将其转换为 64 位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12022862/

相关文章:

c - 为什么键盘中断在 QEMU 中起作用,但在真实硬件上不起作用?

tfs - 在仅 64 位的 IIS 进程中使用 TFS2010 客户端

c - 我的 64 位机器每个内存位置只能存储 4 个字节

linux - 32 位到 64 位 jvm 迁移 - jboss web 应用程序和 linux 服务器

在delphi中匹配指纹的算法

delphi - 如何创建运行时 TCalendarEdit?

string - 查找输入字符串中的子字符串

组装拼图-二元炸弹

c# - 从 C# 代码调用 delphi DLL 函数

html - TIdHTTPServer 改变 HTML