LD_PRELOAD用于C ++类方法 [英] LD_PRELOAD for C++ class methods

查看:185
本文介绍了LD_PRELOAD用于C ++类方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要介入一个C ++程序中的方法调用(该类驻留在一个单独的共享库中)。我想我可以使用LD_PRELOAD,但我不知道这将如何工作(我只找到C函数的例子):是否有一种方法来设置插入一个单一的方法,而不复制任何代码从插入类实现? p>

I need to interpose on a method call in a C++ program (the class resides in a separate shared library). I thought I could use LD_PRELOAD, but i am not sure how this would work (i only found examples of C functions): is there a way to setup interposition for a single method without copying over any code from the interposed class implementation?

推荐答案

它不会很便携,但你可以在C中写入你的插入函数,并给它的C ++方法的名称。你必须明确地处理这个参数,当然,但我认为所有的ELF ABI只是把它看作是一个看不见的第一个参数。

It wouldn't be very portable, but you could write your interposing function in C and give it the mangled name of the C++ method. You would have to handle the this parameter explicitly, of course, but I think all ELF ABIs just treat it as an invisible first argument.

这篇关于LD_PRELOAD用于C ++类方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆