How to print the current thread stack trace inside the Linux kernel?

后端 未结 2 459
清歌不尽
清歌不尽 2020-12-29 11:02

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()<

相关标签:
2条回答
  • 2020-12-29 11:52

    @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:

    • make debug prints along with funcname / line# info (via the usual printk() or trace_printk()) and only if DEBUG mode is On
    • dump the kernel-mode stack
    • print the current context (process or interrupt along with flags in the form that ftrace uses)
    • a simple assert() macro (!)
    • a cpu-intensive DELAY_LOOP (useful for test rigs that must spin on the processor)
    • an equivalent to usermode sleep functionality
    • a function to calculate the time delta given two timestamps (timeval structs)
    • convert decimal to binary, and
    • a few more.

    Whew :-)

    0 讨论(0)
  • 2020-12-29 12:03

    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.

    0 讨论(0)
提交回复
热议问题