aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/call_stack.cpp
blob: 25f398569444a51b80c5854a480c80df7277d4e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "pdb/all.hpp"

#include <boost/config.hpp>
#include <boost/nowide/iostream.hpp>

#include <exception>

namespace test {

typedef void (*F)();

void call_stack() {
    const auto dbghelp = pdb::DbgHelp::current_process();
    const auto call_stack = pdb::CallStack::capture();
    call_stack.dump(boost::nowide::cout, dbghelp);
}

// Some tricks to prevent the functions from being inlined follow...
void baz() {
    boost::nowide::cout << "baz " << &baz << '\n';
    F f = &call_stack;
    f();
}

void bar() {
    boost::nowide::cout << "bar " << &bar << '\n';
    F f = &baz;
    f();
}

void foo() {
    boost::nowide::cout << "foo " << &foo << '\n';
    F f = &bar;
    f();
}

} // namespace test

int main() {
    try {
        test::F f = &test::foo;
        f();
    } catch (const std::exception& e) {
        boost::nowide::cerr << e.what() << '\n';
        return 1;
    }
    return 0;
}