Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ftrace allow capture of system call arguments to the Linux kernel, or only function names?

The goal is to examine arguments passed to specific system calls (e.g. exec, open, etc.) by any process.

From the official documentation, no capability to log function arguments is described (looked mostly at the "function" tracer, as I don't need the graph).

I wanted to make sure I'm not overlooking something and wasting time using something more exotic if I could actually do this within the framework of ftrace.

like image 286
MaxVT Avatar asked Dec 22 '14 18:12

MaxVT


1 Answers

I have limited experience with ftrace, although I have used it for for function stack traces and latency issues. (People with more experience can possibly suggest) Its pretty much the same experience using trace-cmd and kernelshark.

However, if you want to trace syscalls, function params, kernel APIs and return values etc. within the kernel space a better choice would be to go with systemtap. It has an extensive list of Samples & Doc which is good for function call tracing, argument values passed etc. You may want to look at some samples and taylor them to your requirement. See general/para-callgraph-verbose.stp and process/sleeptime.stp

"

general/para-callgraph-verbose.stp - Callgraph Tracing with Verbose Arguments keywords: TRACE CALLGRAPH

Print a timed per-thread microsecond-timed callgraph, complete with pretty-printed function parameters and return values. The first parameter names the function probe points to trace. The optional second parameter names the probe points for trigger functions, which acts to enable tracing for only those functions that occur while the current thread is nested within the trigger.

stap para-callgraph-verbose.stp 'kernel.function("*@fs/proc*.c")' \
'kernel.function("vfs_read")' -c "cat /proc/sys/vm/* || true"

process/strace.stp - Trace system calls keywords: _BEST PROCESS SYSCALL

The script loosely emulates strace, when applied to individual processes or hierarchies (via -c/-x), or the entire system (without -c/-x). A few output configuration parameters may be set with -G.

stap strace.stp -c "sleep 1"

"

Note you will need to install the correct version of the debug kernel and kernel-devel rpms/deb for stap to work correctly. For this just use stap-prep and install the dependencies shown depending on the flavour you are on.

like image 154
askb Avatar answered Oct 13 '22 16:10

askb