- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个可以记录堆栈跟踪的应用程序,以后可以用于调试。
在 Windows 上,我使用了 JEDI 项目提供的出色的 JCLDebug 单元。
现在我的应用程序在 OSX 上运行,我遇到了一些麻烦——我不知道在发生异常时如何获取正确的堆栈跟踪。
我已经掌握了基础知识-
1)我可以使用'backtrace'(在libSystem.dylib中找到)获得堆栈跟踪
2) 可以使用 Delphi 的链接器提供的 .map 文件将生成的回溯转换为行号
我剩下的问题是 - 我不知道从哪里调用回溯。我知道 Delphi 使用 Mach 异常(在单独的线程上),并且我不能使用 posix 信号,但这就是我设法解决的所有问题。
我可以在“try...except” block 中获得回溯,但不幸的是,到那时堆栈已经结束了。
如何安装正确的异常记录器,它将在异常发生后立即运行?
更新:
根据“Honza R”的建议,我查看了“GetExceptionStackInfoProc”程序。
这个函数确实让我“深入”了异常处理过程,但不幸的是,我遇到了一些以前遇到的相同问题。
首先——在桌面平台上,这个函数'GetExceptionStackInfoProc'只是一个函数指针,你可以用你自己的异常信息处理程序来分配它。所以开箱即用,Delphi 不提供任何堆栈信息提供程序。
如果我将一个函数分配给“GetExceptionStackInfoProc”,然后在其中运行一个“回溯”,我会收到一个堆栈跟踪,但该跟踪是相对于异常处理程序,而不是导致异常的线程。
“GetExceptionStackInfoProc”确实包含指向“TExceptionRecord”的指针,但可用的文档非常有限。
我可能超出了我的深度,但是如何从正确的线程中获取堆栈跟踪?我是否可以将自己的“回溯”函数注入(inject)异常处理程序,然后从那里返回到标准异常处理程序?
更新 2
更多细节。需要澄清的一件事 - 这个问题是关于由 MACH 消息处理的异常,而不是完全在 RTL 内处理的软件异常。
Embarcadero 已经列出了一些评论以及这些功能 -
System.Internal.MachExceptions.pas -> catch_exception_raise_state_identity
{
Now we set up the thread state for the faulting thread so that when we
return, control will be passed to the exception dispatcher on that thread,
and this POSIX thread will continue watching for Mach exception messages.
See the documentation at <code>DispatchMachException()</code> for more
detail on the parameters loaded in EAX, EDX, and ECX.
}
System.Internal.ExcUtils.pas -> SignalConverter
{
Here's the tricky part. We arrived here directly by virtue of our
signal handler tweaking the execution context with our address. That
means there's no return address on the stack. The unwinder needs to
have a return address so that it can unwind past this function when
we raise the Delphi exception. We will use the faulting instruction
pointer as a fake return address. Because of the fencepost conditions
in the Delphi unwinder, we need to have an address that is strictly
greater than the actual faulting instruction, so we increment that
address by one. This may be in the middle of an instruction, but we
don't care, because we will never be returning to that address.
Finally, the way that we get this address onto the stack is important.
The compiler will generate unwind information for SignalConverter that
will attempt to undo any stack modifications that are made by this
function when unwinding past it. In this particular case, we don't want
that to happen, so we use some assembly language tricks to get around
the compiler noticing the stack modification.
}
0: MyExceptionBacktracer
1: initunwinder in System.pas
2: RaiseSignalException in System.Internal.ExcUtils.pas
RaiseSignalException
由
SignalConverter
调用,我被引导相信
backtrace
libc 提供的函数与对堆栈所做的修改不兼容。因此,它无法读取超出该点的堆栈,但堆栈仍然存在于下方。
unit MyExceptionHandler;
interface
implementation
uses
SysUtils;
var
PrevRaiseException: function(Exc: Pointer): LongBool; cdecl;
function backtrace2(base : NativeUInt; buffer : PPointer; size : Integer) : Integer;
var SPMin : NativeUInt;
begin
SPMin:=base;
Result:=0;
while (size > 0) and (base >= SPMin) and (base <> 0) do begin
buffer^:=PPointer(base + 4)^;
base:=PNativeInt(base)^;
//uncomment to test stacktrace
//WriteLn(inttohex(NativeUInt(buffer^), 8));
Inc(Result);
Inc(buffer);
Dec(size);
end;
if (size > 0) then buffer^:=nil;
end;
procedure UnInstallExceptionHandler; forward;
var
InRaiseException: Boolean;
function RaiseException(Exc: Pointer): LongBool; cdecl;
var b : NativeUInt;
c : Integer;
buff : array[0..7] of Pointer;
begin
InRaiseException := True;
asm
mov b, ebp
end;
c:=backtrace2(b - $4 {this is the compiler dependent value}, @buff, Length(buff));
//... do whatever you want to do with the stacktrace
Result := PrevRaiseException(Exc);
InRaiseException := False;
end;
procedure InstallExceptionHandler;
var
U: TUnwinder;
begin
GetUnwinder(U);
Assert(Assigned(U.RaiseException));
PrevRaiseException := U.RaiseException;
U.RaiseException := RaiseException;
SetUnwinder(U);
end;
procedure UnInstallExceptionHandler;
var
U: TUnwinder;
begin
GetUnwinder(U);
U.RaiseException := PrevRaiseException;
SetUnwinder(U);
end;
initialization
InstallExceptionHandler;
end.
最佳答案
您可以使用 GetExceptionStackInfoProc
, CleanUpStackInfoProc
和 GetStackInfoStringProc
在 Exception
您需要在 GetExceptionStackInfoProc
中保存堆栈跟踪的类然后用 GetStackInfoStringProc
检索它如果您使用 StackTrace
,它将被 RTL 调用Exception
的属性(property).也许你也可以看看https://bitbucket.org/shadow_cs/delphi-arm-backtrace这在 Android 上演示了这一点。
要在 Mac OS X 上正确执行此操作,libc
backtrace
函数无法使用,因为 Delphi 在调用 GetExceptionStackInfoProc
时会损坏堆栈帧。来自 Exception.RaisingException
.必须使用自己的实现,该实现能够从不同的基地址遍历堆栈,可以手动更正。
您的 GetExceptionStackInfoProc
然后看起来像这样(我在此示例中使用了 XE5,添加到 EBP 波纹管的值可能会根据您使用的编译器而有所不同,并且此示例仅在 Mac OS X 上进行了测试,Windows 实现可能会或可能不会不同):
var b : NativeUInt;
c : Integer;
buff : array[0..7] of Pointer;
begin
asm
mov b, ebp
end;
c:=backtrace2(b - $14 {this is the compiler dependent value}, @buff, Length(buff));
//... do whatever you want to do with the stacktrace
end;
backtrace2
函数看起来像这样(请注意,在实现中缺少停止条件和其他验证,以确保在堆栈遍历期间不会导致 AV):
function backtrace2(base : NativeUInt; buffer : PPointer; size : Integer) : Integer;
var SPMin : NativeUInt;
begin
SPMin:=base;
Result:=0;
while (size > 0) and (base >= SPMin) and (base <> 0) do begin
buffer^:=PPointer(base + 4)^;
base:=PNativeInt(base)^;
Inc(Result);
Inc(buffer);
Dec(size);
end;
if (size > 0) then buffer^:=nil;
end;
关于macos - Delphi - 在 OSX 上获取完整的堆栈跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23039510/
具体详细介绍请看下文: 在使用文件进行交互数据的应用来说,使用FTP服务器是一个很好的选择。本文使用Apache Jakarta Commons Net(commons-net-3.3.jar)
我在日志文件中收到这些警告: WARN 2013-01-15 00:08:15,550 org.eclipse.jetty.http.HttpParser- HttpParser Full for
我在使用特定网页时遇到问题。当我按下链接时,我收到应用程序错误(不是 http 错误等,而是应用程序级别错误)。 但是我打开了开发人员工具和网络控制台,我看到没有请求发送到服务器。 所以我双击并选择查
我没有组装经验,但这是我一直在做的。如果在通过程序集中的指针传递参数和调用函数时缺少任何基本方面,我希望输入。 例如,我想知道是否应该还原ecx,edx,esi,edi,。我读到它们是通用寄存器,但我
我没有组装经验,但这是我一直在做的。如果在通过程序集中的指针传递参数和调用函数时缺少任何基本方面,我希望输入。 例如,我想知道是否应该还原ecx,edx,esi,edi,。我读到它们是通用寄存器,但我
我正在尝试创建完整 uiscrollview 的快照,所有内容大小,我已经搜索了很多,并且我在 SO 上找到了一些东西,如下所示: Getting a screenshot of a UIScroll
我想复制一个包含以下结构的Vector,对我来说重要的是在修改复制的 vector 时保持原始Vector完整: public class objet_poid_n { public int
给定一个示例字符串 s = '嗨,我的名字是 Humpty-Dumpty,来自“爱丽丝,爱丽丝镜中奇遇记”',我想将其分成以下 block : # To Do: something like {l =
已关闭。此问题旨在寻求有关书籍、工具、软件库等的建议。不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以
我正在尝试创建一个正则表达式来查找文本中的 Linux 文件路径,但是正则表达式对我来说非常陌生。我有下面的代码片段,它将识别下面文件结构的开头。 .*(/bin/|/home/).* 完成正则表达式
我正在寻找远程托管的 JPG 的尺寸、宽度和高度。我已经了解了如何通过下载完整图像来执行此操作。 但是,如果我可以通过仅下载足以获取此信息的方式来做到这一点,那将是理想的。 典型的图像大小为 200K
有没有办法让下面的代码: import traceback def log(message): print "%s: %s" %(traceback.extract_stack()[0:-1]
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 3 年前。 Improve this qu
git show 显示了修订版中所做的所有更改。但是,它会打印出所有更改——而不仅仅是文件名。 git show --stat 只显示文件名,但它把它们截断了!有没有办法获得已更改文件名的完整列表?
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想要改善这个问题吗?更新问题,以便将其作为on-topi
当我在模板中调用我的模型 get_absolute_url 方法时,我想要一个绝对/完整的 url。在我的入门模型中,我有以下内容: def get_absolute_url(self): r
我正在使用 jQuery 1.5.1 这是我的代码: $('.cellcontent').animate({ left: '-=190'}, { easing: alert('start
我正在使用下面的方法删除条形图并使用新数据更新条形图,但这样做时出现了一个小故障/完整的图表消失 1 秒,直到加载新数据。但是是否可以通过仅增加/减少柱形而不实际消失图表来实现相同的目的。 d3.se
基于 this question 中的讨论,任何人都可以提供代码或代码链接,显示 NumericLiteralX 模块的完整实现(例如 this one )?我对 NumericLiteralX 模块
我的目标是检索网站的 html,并将其转换为可读的String。我下面的代码可以工作,但我遇到了一个技术问题:当我尝试检索 http://time.gov/HTML5 的 html 时,我在 andr
我是一名优秀的程序员,十分优秀!