编译库的C 挂钩函数用于调试

C++ hook function of compiled library for debugging

本文关键字:函数 用于 调试 编译      更新时间:2023-10-16

用于调试目的,希望在每个呼叫上获得编译库中的某些功能的参数。我知道我可以重新编译库,但是某些库可能需要一半的一天(例如QT)。

在编译库中考虑此功能

class SomeClass
{
public:
    static QString getUpper(const QString &str);
};

包含库中的SomeClass的程序

void printArguments(const QString &str)
{
    qDebug() << str; //here we print argument
}
int main()
{
    //function that I need
    hookFunction((void*)&SomeClass::getUpper, (void*)&printArguments);
    SomeClass::getUpper("Hi"); // here I will see "Hi" in console
}

我发现了一些类似的问题,但是我不需要注射DLL。这是我的程序,包括库。

我找到了解决方案

这个库(polyhook)做我想做的。