获取调用函数调用的C++程序中的所有行号
Get all the line numbers in a C++ program where function calls are invoked
例如,我有一个C++程序:
#include <iostream>
#include<vector>
int main() {
int a =0;
//A vector of size 10 with all values as 1
std::vector<std::size_t> v(10, 1);
assert(v.size() == 10);
return 0;
}
有没有办法找到调用函数调用的行号:
因此,我会在构造向量 v 和调用向量 size(( 函数的位置对数字进行行列。
任何编程语言中的实用程序都是可以接受的,但优先考虑 gdb 解决方案来查找函数调用。
我会在构造向量 v 和调用向量 size(( 函数的地方对数字进行行列。
在 GDB 中没有简单的方法可以做到这一点,但您可以使用objdump -d
来获取CALL
指令的地址。示例:使用您的程序,添加缺少的#include <assert.h>
并使用以下命令构建它:
$ gcc -g t.cc -fno-pie -no-pie
$ objdump -dC a.out | grep 'call.*>::vector'
4011da: e8 f9 00 00 00 callq 4012d8 <std::vector<unsigned long, std::allocator<unsigned long> >::vector(unsigned long, unsigned long const&, std::allocator<unsigned long> const&)>
$ objdump -dC a.out | grep 'call.*>::size'
4011f2: e8 8f 01 00 00 callq 401386 <std::vector<unsigned long, std::allocator<unsigned long> >::size() const>
现在您知道了CALL
指令的地址,您可以使用addr2line
将它们转换为函数/文件/行:
$ addr2line -fe a.out 4011da 4011f2
main
/tmp/t.cc:9
main
/tmp/t.cc:10 (discriminator 1)
相关文章:
- C# DLL 从C++应用程序调用 SOAP Web 服务
- 从C++程序调用 git 克隆
- 使用另一个程序调用正在运行的 C++ 程序中的函数
- C++控制台应用程序调用C++/CLI静态库
- 从 C# Windows 应用程序调用 C dll 会导致 svchost.exe 崩溃
- LoadLibray FileNotFound 取决于哪个应用程序调用
- 为什么无法在 Cocoa 应用程序调用的 C++ func 中嵌入自定义 Python 模块
- 使用模拟器C++从RISC-V裸机程序调用printf系统调用时失败
- C++程序调用 C 函数 在 g++ 链接期间获取未定义的引用
- 使用 gtest 和 gmock 验证程序调用
- 从 Qt 小部件应用程序调用 pyqt widget
- 如何使用Mono / C#程序调用Linux / C ++函数?
- 是否可以通过另一个程序调用程序
- 从应用程序调用静态库时,QT创建者什么都不会发生
- 如何知道库的哪些功能是由程序调用的
- OpenCV 函数在由C++线程程序调用的 Python 脚本本身调用时锁定
- numpy.core.multiarray在通过Xcode中开发的C 应用程序调用Python模块时未能导入
- 如何使用 lamba 作为连接处理程序调用 boost async_connect 作为成员函数
- 如何调试由另一个程序调用的程序
- 从C 程序调用FFMPEG