diff --git a/examples/unwind/doit.sh b/examples/unwind/doit.sh new file mode 100644 index 0000000000000000000000000000000000000000..94c4d26306f2d4ef951b26e727ca1baa99ceb0ce --- /dev/null +++ b/examples/unwind/doit.sh @@ -0,0 +1,18 @@ +#/bin/bash + +function main() +{ + set -e + set -x + g++ unc.c -o unc.exe + $PSZ unc.exe unc-zipr.exe --tempdir unc-temp + + ./unc.exe + ./unc-zipr.exe + + rm -rf unc.exe unc-zipr.exe unc-temp + + +} + +main "$@" diff --git a/examples/unwind/unc.c b/examples/unwind/unc.c new file mode 100644 index 0000000000000000000000000000000000000000..786f0590d0f1da5d66a89c634b53212a4a735471 --- /dev/null +++ b/examples/unwind/unc.c @@ -0,0 +1,22 @@ +#define UNW_LOCAL_ONLY +#include <libunwind.h> + +void show_backtrace (void) { + unw_cursor_t cursor; unw_context_t uc; + unw_word_t ip, sp; + + unw_getcontext(&uc); + unw_init_local(&cursor, &uc); + while (unw_step(&cursor) > 0) { + unw_get_reg(&cursor, UNW_REG_IP, &ip); + unw_get_reg(&cursor, UNW_REG_SP, &sp); + printf ("ip = %lx, sp = %lx\n", (long) ip, (long) sp); + } +} + + +int main() +{ + show_backtrace(); + return 0; +}