I am trying to debug my embedded device by monitoring when system calls are being triggered. As of now I have a root shell connected to the device. When I do the $ top command I can see my executable /system/bin/main is running but within in this file I have multiple ioctl calls. What I want to do is "be notified" or monitor when these system calls are actually being triggered in real time. For example I know I can trigger an ioctl call by sending a request to the camera but I do not know how to view that in the root shell. I am only using ioctl in this file.
1 Answer
There is an utility called strace, which does exactly that: attaches to a program and displays its system calls. You could use it like strace <program>, but then it would be mixing with the normal program output and interfering with it. A better way (that requires root access though) would be to first run the program, then pgrep <program> to get its PID or find it manually via top, and then in a separate shell run as root strace -p <pid>. You could then grep there for ioctl() and pipe that to notify-send or a bell echo via xargs to get notified every time. Also, it is possible to trace just ioctl() by passing -e trace=ioctl to strace, and by adding the -f argument it would also trace any child processes created. A full command would probably look like this:
strace -f -e trace=ioctl -p <pid> 2>&1 | tee ioctl.log | tee >(xargs -L1 echo -e '\a') Omit the last command to simply output the ioctls to the stdout. Swap echo -e \b for a notify-send or any other notification creator of your preference that would get called every time a new ioctl happens.
- Can I use this while the the main file is already in execution? Currently my file runs right after boot so I am not manually starting it with a command. Starting another instance would also not work. @aviroAskedSuperior– AskedSuperior2022-11-09 18:41:03 +00:00Commented Nov 9, 2022 at 18:41
- @AskedSuperior yes, it would attach to any running process.Savchenko Dmitriy– Savchenko Dmitriy2022-11-10 10:31:20 +00:00Commented Nov 10, 2022 at 10:31
stracebut these daysbpftracemight be a better choice.strace -p PID -f -e ioctl(filling in the correct value for the process id of course). otherwise usestrace -f -e ioctl main.