how to dump call stack in syscall(android kernel) ?

送分小仙女□ 提交于 2019-12-09 13:48:23

问题


I want to know who called *sys_reboot* when the phone(android) reboot unexpectly.

Is there a way to dump the call stack in syscall(android kernel)?


回答1:


If all you want it a kernel call trace, you can get that via dump_stack(). panic() calls that, amongst other things. The BUG() / BUG_ON() wrappers give it a more descriptive message and an optional conditional test.

A userland stacktrace, particularly a symbolic one, though, cannot reliably be obtained from within the kernel directly. It's possible to copy the stack memory into kernel space and log the contents, or even heuristically walk SP/FP linkage if framepointers aren't optimized out, but to resolve symbols, it'd need to access and parse ELF information. I'm unsure anyone has done that as pure kernel-side implementation; an easier solution there would be to stop the program from your syscall hook, spawn a userspace debugger attaching to it, extracting a stacktrace, continuing the program when done.

See this SO posting, call_usermodehelper / call_usermodehelperpipe usage for how to do this.

See also this SO posting: How to print the userspace stack trace in linux kernelspace for another reference to the same question.



来源:https://stackoverflow.com/questions/12766901/how-to-dump-call-stack-in-syscallandroid-kernel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!