Debugging by Watching
Sometimes the problems you’re encountering are not that bad and running an application program in user space to examine the way the driver reacts to system calls can help track down minor problems or confirm that the driver is working correctly. For example, I was able to feel confident about scull after looking at how its read implementation reacted to read requests for different amounts of data.
There are various ways to watch a user-space program working. You can run a debugger on it to step through its functions, add print statements, or run the program under strace. The last technique is most interesting when the real goal is examining kernel code.
The strace command is a powerful tool that shows all the
system calls issued by a user-space program. Not only does it show
the calls, but it can also show the arguments to the calls,
as well as return values in symbolic form. When a system call fails,
both the symbolic value of the error (e.g., ENOMEM) and the
corresponding string (Out of memory) are displayed. strace
has many command-line options; the most useful are
-t to display the time when each call is executed,
-T to display the time spent in the call, and -o to
redirect the output to a file. By default, strace prints tracing
information on stderr.
strace receives information from the kernel itself. This means that a program can be traced regardless of whether it was compiled with debugging support (the -g option to gcc) or whether it is stripped. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access