2

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

rid
  • 61,078
  • 31
  • 152
  • 193
Lycan
  • 21
  • 1
  • 2
  • Note that a kernel call stack from `syscall` will be just one level deep ... given that it's the first way into the kernel. Are you sure you want the _kernel_ call stack at this time, or rather the _userland_ one ? – FrankH. Oct 09 '12 at 10:27
  • No, what I actually want is the **user space stack**. So I do not think 'dump_stack()' or 'panic()' can work – Lycan Oct 09 '12 at 11:33
  • You'd need to stop the process / thread, `send_sig_info(SIGSTOP, SEND_SIG_FORCED, current)`, then spawn a _userspace helper_ (`gdb` or the `pstack` script, or a busybox-builtin) to get you the stacktrace, then continue the process. – FrankH. Oct 12 '12 at 08:08

1 Answers1

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.

Community
  • 1
  • 1
FrankH.
  • 17,675
  • 3
  • 44
  • 63