我承认我在这里没有什么经验,但是你看过异常演示代码示例吗?它似乎完全包含你希望找到的那种序列。
基本上,你通过设置个性开始表现为在C++:
llvm::Function *personality = module.getFunction("__gxx_personality_v0");
然后,您可以创建具有个性landingpad并定义其类型:
llvm::LandingPadInst *caughtResult =
builder.CreateLandingPad(ourCaughtResultType,
personality,
numExceptionsToCatch,
"landingPad");
设置的类型赶上:
for (unsigned i = 0; i < numExceptionsToCatch; ++i) {
// Set up type infos to be caught
caughtResult->addClause(module.getGlobalVariable(
ourTypeInfoNames[exceptionTypesToCatch[i]]));
}
并指示它是一个清理处理程序:
caughtResult->setCleanup(true);
这就是我相信;现在你可以得到异常本身:
llvm::Value *unwindException = builder.CreateExtractValue(caughtResult, 0);
的ExceptionDemo.cpp文件,从中提取这些代码段,包含了更充分的序列;具体地讲,它显示了如何检查捕获的异常和分支类型根到特定块 - 你的清理代码 - 当它匹配的东西:
llvm::Value *retTypeInfoIndex = builder.CreateExtractValue(caughtResult, 1);
// FIXME: Redundant storage which, beyond utilizing value of
// caughtResultStore for unwindException storage, may be alleviated
// altogether with a block rearrangement
builder.CreateStore(caughtResult, caughtResultStorage);
builder.CreateStore(unwindException, exceptionStorage);
builder.CreateStore(ourExceptionThrownState, exceptionCaughtFlag);
// Retrieve exception_class member from thrown exception
// (_Unwind_Exception instance). This member tells us whether or not
// the exception is foreign.
llvm::Value *unwindExceptionClass =
builder.CreateLoad(builder.CreateStructGEP(
builder.CreatePointerCast(unwindException,
ourUnwindExceptionType->getPointerTo()),
0));
// Branch to the externalExceptionBlock if the exception is foreign or
// to a catch router if not. Either way the finally block will be run.
builder.CreateCondBr(builder.CreateICmpEQ(unwindExceptionClass,
llvm::ConstantInt::get(builder.getInt64Ty(),
ourBaseExceptionClass)),
exceptionRouteBlock,
externalExceptionBlock);
最后一个附加的例子,有解释等,可on the blog post that introduced the new exception handling mechanism 。
来源
2012-11-06 15:00:48
Oak
该例子ExceptionDemo很有趣,我不知道它,谢谢。引起我注意的一点是,llvm :: Function是为'ourPersonality'创建的,并在着陆板中使用,但是我没有在任何地方看到从该函数到实际'ourPersonality'函数地址的映射。如果映射为空,'getFunction'默认情况下是否执行符号解析?我找不到任何有关'功能'的文档 – lurscher
@lurscher我不知道;我怀疑它和它的定义中定义的_Unwind_Reason_Code有关(它出现在同一个文件中),但我对整个区域恐怕不够熟悉。 – Oak