save_stack_trace_tsk 和结构 stack_trace 在 Linux 5.2+ 中不再可用

save_stack_trace_tsk and struct stack_trace is no longer available in Linux 5.2+

在5.2之前的内核版本中,我使用save_stack_trace_tsk来获取调用堆栈。

但是Linux kernel 5.2+已经没有这个方法了,我该用什么?

自己解决:

unsigned long store[64];

int len = stack_trace_save_tsk(current, store, 64, 0);
for (int i = 0; i < len; i ++) {
    pr_info("stack at %p\n", store[i]);
}

这个问题看起来很诱人所以我在这里做了一些挖掘是我的发现。

TLDR; stack_trace_save() 函数替换为 arch_stack_walk() 接口*

这是合并计划的一部分,删除重复代码。 linux commit 214d8ca6ee854 为遍历堆栈跟踪提供通用架构。

名为 arch_stack_walk 的新界面。 使它更通用。 这发生在 2019 年 4 月 25 日。根据 Kernel release History Wiki 它最后一次更改是在 5.1 中。在 linux commit 3599fe12a125f.

回答你的最后一个问题

what should I use?

save_stack_trace_tsk -> stack_trace_save_tsk

有不同的函数声明。