From 34314d8ea5625214100591df6bdb1457822c6783 Mon Sep 17 00:00:00 2001 From: Jason Hiser <jdhiser@gmail.com> Date: Wed, 17 Jul 2019 11:18:53 -0400 Subject: [PATCH] libunwind test --- examples/unwind/doit.sh | 18 ++++++++++++++++++ examples/unwind/unc.c | 22 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 examples/unwind/doit.sh create mode 100644 examples/unwind/unc.c diff --git a/examples/unwind/doit.sh b/examples/unwind/doit.sh new file mode 100644 index 000000000..94c4d2630 --- /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 000000000..786f0590d --- /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; +} -- GitLab