简体   繁体   English

列出从用户空间到内核空间的ioctl调用

[英]Listing ioctl calls from userspace to kernelspace

Might be my question sounds more naive. 可能是我的问题听起来更天真。

But I wanted to know if it is possible to list the ioctl calls made from user space to kernel space in Linux. 但我想知道是否可以在Linux中列出从用户空间到内核空间的ioctl调用。

Use LTTng . 使用LTTng This is a modern Linux kernel tracer (works in user land too) that installs in seconds (available as packages) if you're using Ubuntu, Fedora, Arch Linux, Debian or openSUSE. 这是一个现代的Linux内核跟踪器(也适用于用户领域),如果您使用的是Ubuntu,Fedora,Arch Linux,Debian或openSUSE,它们可以在几秒钟内安装(作为软件包提供)。 Otherwise, it's still easy getting the tarballs and following the install procedures. 否则, 获取tarball并遵循安装过程仍然很容易。

Tracing 追踪

You create a trace like this: 您创建这样的跟踪:

$ sudo lttng create mySession
Session mySession created.
Traces will be written in /home/user/lttng-traces/mySession-20120619-103600
$ sudo lttng enable-event -k -a --syscall
All kernel system calls are enabled in channel channel0
$ sudo lttng start
Tracing started for session mySession

Then do your normal stuff. 然后做你正常的事情。 All system calls, including ioctl , are recorded/captured by LTTng with interesting parameters. 所有系统调用,包括ioctl ,都由LTTng记录/捕获有趣的参数。 A trace is being written to the /home/user/lttng-traces/mySession-20120619-103600 directory. 正在将跟踪写入/home/user/lttng-traces/mySession-20120619-103600目录。 When you're finished recording, do: 完成录制后,请执行以下操作:

$ sudo lttng stop
Tracing stopped for session mySession
$ sudo lttng destroy
Session mySession destroyed at /home/ephipro

Although destroy doesn't sound good here, it does not actually destroy the trace files; 虽然这里的destroy听起来不太好,但它实际上并没有破坏跟踪文件; it simply flushes everything and frees any link to the files. 它只是刷新所有内容并释放任何文件链接。

sudo is needed everywhere since you are tracing kernel events. 因为您正在跟踪内核事件,所以在任何地方都需要sudo You don't want any user to see all the system calls and their parameters for obvious security reasons. 出于明显的安全原因,您不希望任何用户看到所有系统调用及其参数。

Viewing the trace 查看跟踪

Two main viewers are available now. 现在有两位主要观众。 Babeltrace will give you a text output of all captured events. Babeltrace将为您提供所有捕获事件的文本输出。 You should be able to get it using apt-get ( babeltrace ), otherwise just get the latest tarball . 您应该能够使用apt-getbabeltrace )获取它,否则只需获取最新的tarball Then just use grep to extract the ioctl calls from the huge dump Babeltrace outputs: 然后使用grep从巨大的转储Babeltrace输出中提取ioctl调用:

$ sudo babeltrace /home/user/lttng-traces/mySession-20120619-103600 | grep ioctl
[10:36:41.795425690] (+0.000001403) sys_ioctl: { 1 }, { fd = 18, cmd = 62981, arg = 0 }
[10:36:41.795435996] (+0.000000610) sys_ioctl: { 1 }, { fd = 18, cmd = 2148070920, arg = 139928632507464 }
[10:36:41.795573431] (+0.000008840) sys_ioctl: { 1 }, { fd = 18, cmd = 62982, arg = 4096 }
[10:36:41.795591089] (+0.000000854) sys_ioctl: { 1 }, { fd = 18, cmd = 62981, arg = 38520960 }
[10:36:41.795595956] (+0.000000434) sys_ioctl: { 1 }, { fd = 18, cmd = 2148070920, arg = 139928632507464 }
[10:36:41.796125261] (+0.000006110) sys_ioctl: { 1 }, { fd = 18, cmd = 62982, arg = 0 }
[10:36:41.796185722] (+0.000000947) sys_ioctl: { 1 }, { fd = 18, cmd = 62981, arg = 38530304 }
[10:36:41.796192688] (+0.000000628) sys_ioctl: { 1 }, { fd = 18, cmd = 2148070920, arg = 139928632507464 }
[10:36:41.797155511] (+0.000003280) sys_ioctl: { 0 }, { fd = 18, cmd = 62982, arg = 0 }
[10:36:41.797202362] (+0.000001995) sys_ioctl: { 0 }, { fd = 18, cmd = 62981, arg = 38529760 }
...

What you see here is at which time the event occured, the event name and all its parameters and values. 你在这里看到的是事件发生的时间,事件名称及其所有参数和值。

Eclipse also features a complete LTTng viewer within the Linux Tools plugins project. Eclipse还在Linux Tools插件项目中提供了完整的LTTng查看器。 The easy steps are: 简单的步骤是:

  1. Go to eclipse.org's download page 转到eclipse.org的下载页面
  2. Into Developer Builds (until Eclipse Juno is released in a few days), get Eclipse IDE for C/C++ Developers 进入开发人员构建 (直到Eclipse Juno在几天内发布),获取适用于C / C ++开发人员的Eclipse IDE
  3. Extract it and start it 提取并启动它

Starting from Eclipse Juno, Linux Tools is embedded into Eclipse IDE for C/C++ Developers. 从Eclipse Juno开始,Linux Tools嵌入到Eclipse IDE中,用于C / C ++开发人员。

You may then create a new Tracing project and import the trace. 然后,您可以创建新的跟踪项目并导入跟踪。 If you open the Tracing perspective, you will have access to useful views to visualize the events. 如果打开“ 跟踪”透视图,则可以访问有用的视图以显示事件。 Here's an example of the Histogram and Events views: 以下是直方图事件视图的示例:

Eclipse LTTng查看器

Here I used the Events view to keep only ioctl calls and you can clearly see that the content and time stamps match the Babeltrace output. 在这里,我使用事件视图仅保留ioctl调用,您可以清楚地看到内容和时间戳与Babeltrace输出匹配。

did you try strace ? 你试过strace吗? it list all syscalls. 它列出了所有系统调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM