未捕获的异常——调试技术(C++)
我遇到了一个奇怪的场景,其中以下不太可能的代码:
try{
throw Core::ValueError();
}
catch (Core::Error &e){
...
}
(ValueError 继承自 Error 继承自 std::exception)
会导致如果编译到可执行文件中则捕获异常,但如果编译到特定共享库中则不会捕获异常。
所以我的问题是:
我可以使用哪些调试工具和/或技术来查看异常处理过程的黑匣子内部?我可以用gdb单步调试它吗?
我是否可以从 Mach-o 标头中提取任何信息,这些信息可以告诉我有关某些 catch 子句对某些异常的可捕获性(如果您愿意的话)的任何信息?特别是,我可以查看“gcc_except_tab”部分及其可爱的 LSDA、符号表或其他部分,并推断出符号可见性的任何问题或与捕获异常相关的其他问题吗?
我确实找到了一个在线资源,声称使用一只鸡、七个老鼠尾巴和一个粒子加速器来解决问题,但我想我应该先尝试 StackOverflow,然后将黑魔法作为最后的手段。
(我在 OSX 10.6.7 上运行 i686-apple-darwin10-g++-4.2.1)
I have encountered a curious scenario in which the following unlikely code:
try{
throw Core::ValueError();
}
catch (Core::Error &e){
...
}
(ValueError inherits from Error inherits from std::exception)
results in the exception being caught if compiled into an executable, but not if compiled into a particular shared library.
And so my questions:
What debugging tools and/or techniques can I use to peek inside the black-box that is the exception handling process? Can I step through it with gdb?
Is there any information I could pull out of the Mach-o headers that would tell me anything about the catchablility (if you will) of certain exceptions by certain catch clauses? In particular, can I look say at the "gcc_except_tab" section with its lovely LSDA's, or the symbols table, or another part, and deduce any problem with symbol visibility or other issue relevant to catching exceptions?
I did find an online source that claimed a solution using a chicken, seven rat tails and a particle accelerator, but I figured I'd try StackOverflow first and leave the black magic as a last resort.
(I'm running i686-apple-darwin10-g++-4.2.1 on OSX 10.6.7)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在抛出一个临时对象,因此您应该
catch(Core::Error const& e)
。You are throwing a temporary object so you should
catch( Core::Error const& e )
.