I'm trying to find a way to monitor Process
by hooking
it's function.
[Process] [thirdparty]
... trigger callback
pc --> myfunc(st *s, int b); ------------> handle_myfunc_call(ctx) {
st *s = (st*)ctx->rax;
s->xxx //do some statistics
}
return
<--------
...
[Process] [thirdparty]
I know the easiest way is using eBPF with uprobe. But I need another way which may work under old linux kernel like 3.10.
USTD
Programmer needs to add a hook
in source code which is not I want.
uprobe
I'm familiar with writting kprobe with kernel mod. But after searching Google, I find most uprobe
sample are like this
echo 'p:myfunc binaddr:offset %x0 %x1' > uprobe_events
cat /sys/kernel/tracing/trace_pipe
It seems that uprobe
just print the log but not calling some callback
systemtap
As far as i know systemtap
is using uprobe
(fix me) to attach user function, but I don't know the detail about how it works. It seems using uprobe
like systemtap
works for me.
Utrace
deprecated
Like gdb attach
Thirdparty run as the parent of Process
ptrace
Rewrite instructions (like gdb break
command)
Capture singal
Access the register
I think it's not easy and singal
may cost a lot CPU time...