Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you need to save the stack trace and process its elements somehow, <code>save_stack_trace()</code> or <code>dump_trace()</code> might be also an option. These functions are declared in <code>&lt;linux/stacktrace.h&gt;</code> and <code>&lt;asm/stacktrace.h&gt;</code>, respectively.</p> <p>It is not as easy to use these as <code>dump_stack()</code> but if you need more flexibility, they may be helpful. </p> <p>Here is how <code>save_stack_trace()</code> can be used (replace <code>HOW_MANY_ENTRIES_TO_STORE</code> with the value that suits your needs, 16-32 is usually more than enough):</p> <pre><code>unsigned long stack_entries[HOW_MANY_ENTRIES_TO_STORE]; struct stack_trace trace = { .nr_entries = 0, .entries = &amp;stack_entries[0], .max_entries = HOW_MANY_ENTRIES_TO_STORE, /* How many "lower entries" to skip. */ .skip = 0 }; save_stack_trace(&amp;trace); </code></pre> <p>Now <code>stack_entries</code> array contains the appropriate call addresses. The number of elements filled is <code>nr_entries</code>.</p> <p>One more thing to point out. If it is desirable not to output the stack entries that belong to the implementation of <code>save_stack_trace()</code>, <code>dump_trace()</code> or <code>dump_stack()</code> themselves (on different systems, the number of such entries may vary), the following trick can be applied if you use <code>save_stack_trace()</code>. You can use <code>__builtin_return_address(0)</code> as an "anchor" entry and process only the entries "not lower" than that.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload