How to output function stack in Linux Kernel

In Linux Kernel, we usually trace/debug what kind of events will trigger the phenomena we find in the system. For example, what kind of event will trigger the fact that the timeslice of one process will be very short. In order to solve these kind of problems, we need to output the function stack.

Currently, there are two easy ways to solve this question.
1, Add some output information in each function before that phenomena happens so that you can find what kind of events may trigger it. However, sometimes, in complex system (like Linux kernel), something happens with no clues and we may lose in the sky. Way 2 will make this solution better.

2, Call the function to output the call stack before the phenomena. In Linux kernel, just call dump_stack() function and you will find your way. Dump_stack() in Linux Kernel is used to output call stack information when there is a kernel crash/panic but we can also use it for debugging/tracing.

Answered by harryxiyou.

Weiwei Jia

Weiwei Jia is a Ph.D. student in the Department of Computer Science at New Jersey Institute of Technology since 2016. His research interests are include storage systems, operating systems and computer systems.

Leave a Reply

Your email address will not be published. Required fields are marked *