0

我现在正在学习 Intel pin,我在 pintool 的 main 函数中编写了以下代码。

try
{
    throw std::exception("test daniel");
}
catch (std::exception& e)
{
    printf(e.what());
}

运行它(pin.exe -t Test.dll -- calc.exe),但它只是崩溃了,这肯定是由于未捕获的异常。但我想知道为什么我的“catch”代码失败了。

任何人都知道原因,或者如何在 pintool 中捕获异常?

4

1 回答 1

1

下面是如何在 pintool 中捕获抛出的异常,假设您拥有所有必需的编译选项。应该注意的是,这个简单的 pintool 除了捕获 pin 或工具(而不是应用程序)抛出的异常之外,并没有做任何事情。

您会注意到异常处理函数的注册发生在 PIN_StartProgram() 函数之前,否则将忽略异常。

最后,虽然文档中没有提到,但我希望在调用 PIN_AddInternalExceptionHandler() 之后和 PIN_StartProgram() 之前抛出的异常不会被处理程序捕获。相反,我希望处理程序能够捕获在 PIN_StartProgram() 之后引发的异常,但同样,文档中没有提到它。

//-------------------------------------main.cpp--------------------------------
#include "pin.h"
#include <iostream>


EXCEPT_HANDLING_RESULT ExceptionHandler(THREADID tid, EXCEPTION_INFO *pExceptInfo, PHYSICAL_CONTEXT *pPhysCtxt, VOID *v)
{
    EXCEPTION_CODE c = PIN_GetExceptionCode(pExceptInfo);
    EXCEPTION_CLASS cl = PIN_GetExceptionClass(c);
    std::cout << "Exception class " << cl;
    std::cout << PIN_ExceptionToString(pExceptInfo);
    return EHR_UNHANDLED ;
}

VOID test(TRACE trace, VOID * v)
{
    // throw your exception here
}

int main(int argc, char *argv[])
{
    // Initialize PIN library. This was apparently missing in your tool ?
    PIN_InitSymbols();
    if( PIN_Init(argc,argv) )
    {
        return Usage();
    }

    // Register here your exception handler function
    PIN_AddInternalExceptionHandler(ExceptionHandler,NULL);

   //register your instrumentation function 
   TRACE_AddInstrumentFunction(test,null);

    // Start the program, never returns...
    PIN_StartProgram();

    return 0;
}
于 2016-01-04T23:09:08.880 回答