在抽象类中使用shared_ptr时,如何在nm或objdump中找到函数符号
How to find the function symbol in nm or objdump when using shared_ptr for abstract class?
我使用shared_ptr作为抽象类ABC。ABCImpl类是ABC的实现。Abc_ptr是shared_ptr<指向一个ABCImpl对象。在调用函数中,abc_ptr将调用ABC类中的成员函数之一(func_in_ABC)。编译成功。但是当我使用nm或objdump时,我只能看到abc_ptr的符号。调用函数中没有显示func_in_ABC()的符号。>
有谁知道为什么,或者我如何在调用函数中获得func_in_ABC()符号的输出?
代码如下:在ABC.h:
#include <boost/shared_ptr.hpp>
class ABC
{
public:
virtual void func_in_ABC(const int param) = 0;
};
typedef boost::shared_ptr<ABC> ABCPtr;
ABCPtr get_ABC_ptr();
在ABCImpl.h: #include "ABC.h"
class ABCImpl : public
{
public:
ABCImpl() {}
void func_in_ABC(const int param);
private:
int data;
};
在ABCImpl.cpp: #include "ABCImpl.h"
ABCPtr get_ABC_ptr()
{
return ABCPtr(new ABCImpl());
}
void ABCImpl::func_in_ABC(const int param)
{
data = param;
}
调用者函数d.p p:
#include "D.h"
#include "ABC.h"
void D::call_ABC()
{
ABCPtr abc_ptr = get_ABC_ptr();
abc_ptr->func_in_ABC(100);
}
D.o从nm的输出:
U _Unwind_Resume
U get_ABC_ptr()
0000000000000000 T D::call_ABC()
0000000000000000 W boost::shared_ptr<ABC>::operator->() const
0000000000000000 r boost::shared_ptr<ABC>::operator->() const::__PRETTY_FUNCTION__
U __assert_fail
U __gxx_personality_v0
如果我改变了ABC.h中func_in_ABC的定义,d.p p的编译将会失败。我认为在编译D.o时会检查类ABC的定义,但是为什么我找不到调用者映射到ABC定义的符号?
由于func_in_ABC
是一个虚函数,因此实际上不需要符号名称来调用它。您只需要将该特定虚函数的偏移量放入虚表。
如果您使func_in_ABC
非虚拟,您应该看到nm
输出中出现符号。
相关文章:
- objdump 不显示机器代码,但显示 ASM
- 关于这个在 Linux 上使用 gcc 编译的程序中的 vtable,nm 告诉我什么?
- 未定义的引用(但 nm 表示该函数存在)
- NM 符号名称略有不同
- OBJDUMP给出了具有和没有-fpic的对象文件的相同输出
- 即使存在NM报告符号,在运行时的符号查找错误也是如此
- objdump 和 objcopy 作为 C/C++ 库
- 如何读取NM命令:NM选项-T和-U(未定义)是什么意思
- 如何获取与 objdump 输出的标签相对应的 ELF 二进制文件中的文件偏移量
- 如何使用 objdump 反汇编 OpenJDK(bin/java)
- nm 未知命令行参数 '-C'?
- C++ objdump 使用和拆卸
- Boost 1_65_1 不能使用 OpenSSL 1.1.0g "undefined reference" 编译,但可以使用 "nm"
- 如何比较nm输出
- 是否可以通过NM仅打印用户定义的变量
- 如何使用objdump在高度优化的对象文件中交错源代码
- Clang linker 报告"symbol not found",尽管'nm -m'透露该名称存在于正在链接的库中
- 使用objdump或gcc-c将程序集指令转换为二进制指令
- Android - NDK 共享库,使用 nm / objdump 提取相关的 JNI 钩子
- 在抽象类中使用shared_ptr时,如何在nm或objdump中找到函数符号