3

So, when I call dump_stack(), it printk's to dmesg. But, I need it to, let's say, 'print' it to char array, so that I could display the stack much, much later, in a different place.

Is it possible? It would help me sooo much with debugging a nasty bug I'm having!

user905747
  • 613
  • 1
  • 9
  • 18
  • You could implement a custom dump_stack() in the kernel (e.g., dump_stack_to_buffer(...)) that would send the same stack info to a char buffer. – Peter L. Feb 27 '14 at 20:53
  • 1
    And how would I do that? – JJS Feb 27 '14 at 21:20
  • 1
    @IanTraum Go to the place in the kernel source where dump_stack() is implemented, copy it replacing the function name, then replace printk() with a buffer copy or sprintf(). If this were to be a permanent change that you would want to upstream you might design it more elegantly. This should work for debugging. – Peter L. Feb 27 '14 at 23:45
  • See replies to http://stackoverflow.com/questions/5863122/how-to-include-c-backtrace-in-a-kernel-module-code/, especially Eugene's reply. – Jonathan Ben-Avraham Aug 09 '16 at 13:21

1 Answers1

0

The tool that you need is called save_stack_trace.

First read Baruch's Linux kernel deferred stack trace blog. Then read Eugene's answer to a similar SO post.

Community
  • 1
  • 1
Jonathan Ben-Avraham
  • 4,615
  • 2
  • 34
  • 37