These skills are summed up when I read them. I will talk about them whenever I think of them. In fact, I have summarized more than these skills, but let's talk about them first. I thought about it later. Only when I encountered actual problems when I got the code for analysis can I find some solutions.
In fact, the Linux kernel source code is still difficult to track. When I first read the kernel source code, I felt a lot of things were lost when I was looking for them.
After reading some articles, I found that the kernel is quite helpful. After knowing its temper, the rest is patience.
1. I used VI for a while. After installing a bunch of plug-ins, I found that I still could not feel the many benefits that the advocates mentioned. I still liked sourceinsight. Okay, let's get started. First, we need to solve the problem that the function or variable cannot find the definition, as shown in that the variable on sourceinsight is black and cannot be found everywhere.
For example, we can see that:
Int bus_register (struct bus_type * Bus)
{
...
Subsys_set_kset (bus, bus_subsys );
Retval = subsystem_register (& bus-> subsys );
...
}
Bus_subsys.
We found bus_subsys which could not find the definition. It must be the kernel and we are hiding. At this time, can we find some obvious "definition traces", such as subsys or _ subsys in bus_subsys. There are new discoveries. We found such a macro.
# Define decl_subsys (_ name, _ type, _ uevent_ops )/
Struct subsystem _ name ##_ subsys = {/
. Kset = {/
. Kobj = {. Name = _ stringify (_ name )},/
. Ktype = _ type ,/
. Uevent_ops = _ uevent_ops ,/
}/
}
Let's look back at the source file and header file containing bus_register and find the line of static decl_subsys (bus, & ktype_bus, null); Code.
I do not recommend that you go to the Internet to find something like this. Although there are many articles about the kernel online, they will not detail all the details, when you are always dealing with problems independently, why don't we exercise more in advance?
2. there are many kernel sequence problems, such as the initialization sequence, such as module_init ,__ initcall. In this case, folders and files are ordered during compilation, in addition, the order of different macros is exquisite, so you must pay attention to this when analyzing the module. This is only worth noting. If you are not familiar with a module, it is impossible to understand everything. For example, I sometimes forget to analyze something. However, the longer I look at the kernel, the more frequently-used methods of the kernel, the more I find out, that's the three seeds and two dates.
3. We need to solve the heap pointer during kernel running. This is the soil method used for my own debugging. I will use dump_stack to print out the order in key areas. Because we are working on embedded devices, we often cannot use advanced tools such as kgdb for online debugging, and this method basically does not increase other performance overhead.
4. Multiple definitions do not know which one to use. This is basically because Linux supports a large number of CPUs.
We can use GDB static analysis, objdump, nm, and other tools to precisely locate some functions and variables, or perform step-by-step analysis based on macros, for example, if it is MIPS, we will go to MIPS and take this step.
5. Be aware that you are facing the operating system. Not only applications with C files and header files, makefile, link files, and kconfig should be your friends. When you look at a module or a small part of the code you are interested in, you can first use makefile and kconfig to narrow down the scope of your attention. In fact, regarding the importance of makefile and kconfig, fudan_abc emphasizes a lot in his Linux, but to be honest, it is quite fun to read the fudan_abc article, unfortunately, it seems that it is useless. I have learned a bunch of concepts and cannot be connected. I don't know whether it is my ability to understand or whether Comrade Ren qiaowei is not clear at all. Haha.