linux - Systemtap 脚本到 C 代码的转换和编译

标签 linux gcc architecture systemtap

我的学期项目是网络级反恶意软件 S/W。它的主要组件是 Manager 和 Agent。 代理向管理器提供:

1. CPU usage, Memory usage and B/W usage information

2. Network related Information - 

    Network Profiling
    Function calls from Network Sockets
    TCP packets related information

3. Disk Related Information - 

    I/O monitoring
    File Read/Writes
    File Attribute changes

4. General Profiling

    Function calls
    Call Graph
    Frequently used system calls
    call volume per process

这四个功能中的每一个都以线程的形式实现。我们的平台是 Linux。我们找到了一个名为 systemtap 的工具...

http://sourceware.org/systemtap/SystemTap_Beginners_Guide/useful-systemtap-scripts.html

我们发现这是一个更好的选择,而不是利用 top、ifstat、tcpdump 等 linux 命令。实际上,所有要做的就是从 Agent Java 程序调用脚本或可执行文件。

“systemtap”使用的所有脚本都是用systemtap脚本语言编写的。前端工具(stap)将该脚本转换为C代码,然后将其编译为内核文件。

stap --tmpdir=/home/test/nettop.stp

通过上面的命令,我成功地获得了转换后的C代码文件。但由于依赖性问题,该文件未被编译。

gcc nettop.c nettop.c:10:29: fatal error : runtime_defines.h: 没有那个文件或目录 编译终止。

gcc -B/usr/share/systemtap/runtime/-B/usr/src/kernels/3.3.1-3.fc16.x86_64/include/nettop.c nettop.c:10:29: fatal error : runtime_defines.h: 没有那个文件或目录 编译终止。

gcc --sysroot=/usr/nettop.c nettop.c:10:29: fatal error : runtime_defines.h: 没有那个文件或目录 编译终止。

systemtap 运行时 header 都使用 linux/header 格式,表示 systemtap 的类路径设置为/usr/../../../。 。/包括。将所有标题复制到特定文件夹很容易,但编辑它们以反射(reflect)正确的路径名是不可能的。有 106 个运行时 header 引用了超过一千个 linux header 。

一个。 如何让 gcc 使用特定文件夹作为库?

是否有比此代理架构更好的替代方案?

PS:希望问题不是太含糊。感谢您提前回复。

最佳答案

不要尝试手动编译 systemtap 的中间 C 代码。相反,通过 stap(或通过 staprun 编译的 .ko)运行脚本,并通过 stdout 使用它们的输出。

关于linux - Systemtap 脚本到 C 代码的转换和编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10094468/

相关文章:

c - 使用 SWIG 将指向结构的指针从 TCL 传递到 C 函数

c - 子进程执行时,OS把argv和argc存放在哪里?

java - 具有静态方法的辅助类工厂?

c# - 多层架构中的身份验证

Node.js - 将 `fork()` 与 node-ffi 或附加组件一起使用是否安全?

linux - 解释来自/proc/[id]/mountstats 或/proc/self/mountstats 的数据

c - 在 C 中抑制 'uninitialized variable warnings' 的不同方法

c - "Array index in initialiser exceeds array bounds"

linux - Linux内核模块的缺点?

linux - 为什么这个 bash 函数只打印整个字符串的第一个单词?