delphi 随时获取指定线程的EurekaLog调用栈[duplicate]

ibps3vxo  于 2023-03-08  发布在  其他
关注(0)|答案(1)|浏览(134)
    • 此问题在此处已有答案**:

Get the call stack from EurekaLog at any time(2个答案)
昨天关门了。
是否可以毫无例外地获取具有指定线程id的线程的当前调用堆栈?
一个月一个月

9o685dep

9o685dep1#

根据EurekaLog的文档How to... get background thread call stack?TEurekaCallStack类有一个BuildForThread()方法,您可以将线程句柄和线程ID传递到该方法,例如:

procedure TForm1.Button1Click(Sender: TObject);
var
  CallStack: TEurekaBaseStackList;
  Suspended: Boolean;
begin
  CallStack := EurekaCallStackClass.Create(nil);
  try
    CallStack.BuildForThread(YourThreadHandle, YourThreadId, 
      // Replace with your thread's handle and ID.
      // Thread handle must have:
      // THREAD_GET_CONTEXT, THREAD_QUERY_INFORMATION, and THREAD_SUSPEND_RESUME access rights
      // DO NOT PASS GetCurrentThread and GetCurrentThreadId!!!
      // There is also .BuildForThreadByID method, which does not require thread handle argument.

      nil, // first addr
      [ddUnit, ddProcedure, ddSourceCode], // CurrentEurekaLogOptions.csoDebugInfo
      True, // get debug info?
      False, // show begin calls?
      TracerRawEurekaLogV7Mask, // CurrentEurekaLogOptions.csoAllowedRenderMethods
      True, // running thread?
      @Suspended); // will return True if thread was suspended before call stack is taken
 
    Memo1.Lines.Assign(CallStack);
  finally
    FreeAndNil(CallStack);
  end;
end;

同一页上还写着:

**重要说明:**请注意后台线程将继续运行。例如,其实际调用堆栈可能与您使用的调用堆栈不同。

您可能还对EFreeze单元中的RaiseFreezeException例程感兴趣,该例程将为指定的单个线程创建报告。

相关问题