systemstap中自定义函数

Embedded C can be the body of a script function. Instead enclosing the function body statements in { and
}, use %{ and %}. Any enclosed C code is literally transcribed into the kernel module: it is up to you to make
it safe and correct. In order to take parameters and return a value, macros STAP_ARG_* and STAP_RETVALUE
are made available. The familiar data-gathering functions pid(), execname(), and their neighbours are all
embedded C functions. Figure 10 contains another example.

Since systemtap cannot examine the C code to infer these types, an optional annotation syntax is available
to assist the type inference process. Simply suffix parameter names and/or the function name with :string
or :long to designate the string or numeric type. In addition, the script may include a %{ %} block at the
outermost level of the script, in order to transcribe declarative code like #include <linux/foo.h>. These
enable the embedded C functions to refer to general kernel types.
There are a number of safety-related constraints that should be observed by developers of embedded C code.
1. Do not dereference pointers that are not known or testable valid.
2. Do not call any kernel routine that may cause a sleep or fault.
3. Consider possible undesirable recursion, where your embedded C function calls a routine that may be
the subject of a probe. If that probe handler calls your embedded C function, you may suffer infinite
regress. Similar problems may arise with respect to non-reentrant locks.
4. If locking of a data structure is necessary, use a trylock type call to attempt to take the lock. If that
fails, give up, do not block.

下面是tutorial中发出来的一个例子:

# cat embedded-C.stp
%{
#include <linux/sched.h>
#include <linux/list.h>
%}
function task_execname_by_pid:string (pid:long) %{
struct task_struct *p;
struct list_head *_p, *_n;
list_for_each_safe(_p, _n, &current->tasks) {
p = list_entry(_p, struct task_struct, tasks);
if (p->pid == (int)STAP_ARG_pid)
snprintf(STAP_RETVALUE, MAXSTRINGLEN, "%s", p->comm);
}
%}
probe begin;
{
printf("%s(%d)\n", task_execname_by_pid(target()), target())
exit()
}

https://sourceware.org/systemtap/tutorial.pdf

使用最新的systemtap去使用print_backtrace呀,并且最后一定要make install

@在stap中都是有特殊的意义的,比如@count, @define @const(转化成内核定义的宏)

In addition, you can take their address (the &operator), pretty-print structures (the $ and $$ suffix), pretty- print multiple variables in scope (the
$$vars and related variables), or
cast pointers to their types (the @cast operator), or
test their existence / resolvability (the @defined operator).

@__private30是啥意思

systemtap如何写C函数 捎带着看看ret kprobe怎么用的更多相关文章

  1. 用javascript 写个函数返回一个页面里共使用了多少种HTML 标签

    今天我无意间看到一个面试题: 如何用javascript 写个函数返回一个页面里共使用了多少种HTML 标签? 不知你看到 是否蒙B了,如果是我 面试,肯定脑子嗡嗡的响.... 网上搜了搜也没有找到答 ...

  2. PHP写文件函数

    /** * 写文件函数 * * @param string $filename 文件名 * @param string $text 要写入的文本字符串 * @param string $openmod ...

  3. ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)

    1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 154  Solved: 112[ ...

  4. 有一字符串,包含n个字符。写一函数,将此字符串中从第m个字符开始的全部字符复制成为另一个字符串。

    [提交][状态][讨论版] 题目描述 有一字符串,包含n个字符.写一函数,将此字符串中从第m个字符开始的全部字符复制成为另一个字符串. 输入 数字n 一行字符串 数字m 输出 从m开始的子串 样例输入 ...

  5. 假如现在有一堆长度大于3小于9的电话号码,用座机呼叫,如果出现这样的号码【123和12345】那么12345将永远不会被拨出,因为拨到123的时候电话已经呼出了,试写一个函数输出所有不能被呼出的电话号码(java实现)

    解题: 假如现在有一堆长度大于3小于9的电话号码,用座机呼叫,如果出现这样的号码[123和12345]那么12345将永远不会被拨出,因为拨到123的时候电话已经呼出了,试写一个函数输出所有不能被呼出 ...

  6. Java-集合(没做出来)第四题 (List)写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列。 例如: List list = new ArrayList(); list.add(“Hello”); list.add(“World”); list.add(“Learn”); //此时list 为Hello World Learn reverseL

    没做出来 第四题 (List)写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列. 例如: List list = new ArrayList(); list.a ...

  7. 面试题-->写一个函数,返回一个数组中所有元素被第一个元素除的结果

    package com.rui.test; import java.util.Random; /** * @author poseidon * @version 1.0 * @date:2015年10 ...

  8. 【C解毒】怎样写main()函数

    [C解毒]怎样写main()函数(出处: CUNIX论坛)

  9. PHP写日志函数

    初学,写一个函数用于存储日志调试. function WriteLog($msg) { $filename = dirname(__FILE__) ."\\Debug.log"; ...

随机推荐

  1. npm ERR! code ENOENT (未找到文件 error no entry)

    问题: ENOENT一般是没找到文件或路径,包括因为权限问题没找到的情况 解决: 我这个是 目录选择错了 其他:

  2. checkbox的第三种状态--不确定状态

    视觉上,checkbox有三种状态:checked.unchecked.indeterminate(不确定的).看起来就像这样子:

  3. VMware下CentOS7安装后,还原虚拟网络后,敲ifconfig不显示局域网ip解决方法

    VMware下CentOS7安装后,还原虚拟网络后,敲ifconfig不显示局域网ip,没有出现eth0网卡,不能上网,SSH不能连接,输入ifconfig后如下图: 解决方法: 1.编辑网卡的配置文 ...

  4. 【tp5.1】七牛云上传图片

    composer安装: composer require qiniu/php-sdk 配置使用: 在tp5.1的配置文件app.php中配置七牛云的参数 'qiniu' => [ 'access ...

  5. chromedriver各个版本的下载

    驱动的下载地址如下: http://chromedriver.storage.googleapis.com/index.html 注意:64位向下兼容,直接下载32位的就可以啦,亲测可用.

  6. dotnet core 项目

    项目 常用命令 我们使用dotnet core 命令行来创建项目及进行编译,发布等,比较常用的dotnet core 命令 如下: dotnet new [arguments] [options] 创 ...

  7. 【Java】关于Spring MVC框架的总结

    SpringMVC是一种基于Java,实现了Web MVC设计模式,请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将Web层进行职责解耦.基于请求驱动指的就是使用请求-响应模型,框架的 ...

  8. Java——equals方法---18.10.18

    一.equals方法定义 public boolean equals(Object obj)方法 //提供对象是否“相等”的逻辑 二.”equals“和“==”的区别 1.“==”比较的是两个变量本身 ...

  9. 你真的了解React吗

    https://zhufengzhufeng.github.io/zhufengreact/index.html#t21.%E4%BB%80%E4%B9%88%E6%98%AFReact?

  10. 发布npm包 登录报错 E409 Conflict

    1.到官网注册个账号,并且验证完邮箱:https://www.npmjs.com/ 2.打开cmd命令行 登录:$npm login 根据提示 一步步完成登录. 3.新建一个项目文件夹: npmtes ...