1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <assert.h>
16#include <sel4debug/stack_trace.h>
17
18#define STACK_TRACE(x) do { \
19    void *frame = __builtin_frame_address(x); \
20    if (!frame) return; \
21    void *ret = __builtin_return_address(x); \
22    assert(ret); \
23    void *addr = __builtin_extract_return_addr(ret); \
24    printf("Possible stack call (%d) from %p with frame at %p\n", x, addr, frame); \
25    } while (0) \
26    /**/
27
28void print_stack_trace(void) {
29    STACK_TRACE(0);
30    STACK_TRACE(1);
31    STACK_TRACE(2);
32    STACK_TRACE(3);
33    STACK_TRACE(4);
34    STACK_TRACE(5);
35    STACK_TRACE(6);
36    STACK_TRACE(7);
37    STACK_TRACE(8);
38    STACK_TRACE(9);
39    STACK_TRACE(10);
40}
41