Linux Debug Tricks
This page contains many helpful suggestions for debugging issue with the Linux kernel.
Common Tools
- grep : The kernel has thousands of files. The grep tool is the most powerful way to find what you are looking for. Use the -R to search recursively . Remember that grep is case sensitive by default, so use -i if you need it to ignore case.
- And example to find a function name start_kernel: $ grep -r "start_kernel"
- find : Sometimes someone will give you just a filename, and the find command can help you find where that file is. Also, it find is very helpful when combined with grep.
- For example, if you just want to search header files: $ find * -name "*.h" | grep purple
Error Messages
- Many times an error message will be printed out. This happens a lot for a device driver that has trouble initializing during boot.
- Your first step should be to find what source code file is print that message
- Simply use the grep command with -R option and search for that error message.
Error Codes
- If a error message prints out an error code, for example "-110", you should look up what the error code means.
- You can find a list of the error code numbers mean in file include/uapi/asm-generic/errno-base.h
- Since the code will use the #defrine name (not the actual number), you can then search driver file for when that error code/name is returned.
Finding the Device Driver File
- When adding or configuring a driver to your system, you will probably be editing the Device Tree.
- If there is an issue with that driver or peripheral, you will need to find the source code for the driver
- You can use the "compatible" name listed in the device tree, and grep, in order to find the location of the device driver file.
- Do you search starting in the "drivers" directory (to avoid all the matches that will be found in other device tree files)
- For example, to find the UART driver:
$ cd drivers $ grep -R "renesas,sci" *