I would like to be able to print the stack trace of a thread in the Linux kernel.
In details: I want to add code to specific functions (e.g. swap_writepage()<
@rakib is exactly right of course.
In addition, I'd like to point out that one can define simple and elegant macros that help print debug info as and when required. Over the years, I've put these macros and conveneince routines into a header file; you can check it out and download it here: "A Header of Convenience".
There are macros / functions to:
Whew :-)
Linux kernel has very well known function called dump_stack()
here, which prints the content of the stack. Place it in your function in according to see stack info.