aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYichao Zhou <broken.zhou@gmail.com>2017-04-13 22:06:19 +0200
committerJustin M. Keyes <justinkz@gmail.com>2017-07-23 17:02:06 +0200
commit5fc775e2efd1adf4985d9abcb1d970dcaa944555 (patch)
tree450932ce66134b24527dfb9d162f3928c8e840bf
parentca32eb31b87ea63fd36cb6ef181edaf3bf755a81 (diff)
downloadrneovim-5fc775e2efd1adf4985d9abcb1d970dcaa944555.tar.gz
rneovim-5fc775e2efd1adf4985d9abcb1d970dcaa944555.tar.bz2
rneovim-5fc775e2efd1adf4985d9abcb1d970dcaa944555.zip
log.h: LOG_CALLSTACK
-rw-r--r--src/nvim/log.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/nvim/log.h b/src/nvim/log.h
index 221f0bbaf6..48be7606e7 100644
--- a/src/nvim/log.h
+++ b/src/nvim/log.h
@@ -61,6 +61,30 @@
__VA_ARGS__)
#endif
+#if defined(__linux__)
+# include <execinfo.h>
+# define LOG_CALLSTACK(prefix) \
+ do { \
+ void *trace[100]; \
+ int trace_size = backtrace(trace, 100); \
+ \
+ char exe[1024]; \
+ ssize_t elen = readlink("/proc/self/exe", exe, sizeof(exe) - 1); \
+ exe[elen] = 0; \
+ \
+ for (int i = 1; i < trace_size; i++) { \
+ char buf[256]; \
+ snprintf(buf, sizeof(buf), "addr2line -e %s -f -p %p", exe, trace[i]); \
+ FILE *fp = popen(buf, "r"); \
+ while (fgets(buf, sizeof(buf) - 1, fp) != NULL) { \
+ buf[strlen(buf)-1] = 0; \
+ do_log(DEBUG_LOG_LEVEL, __func__, __LINE__, true, prefix "%s", buf); \
+ } \
+ fclose(fp); \
+ } \
+ } while (0)
+#endif
+
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "log.h.generated.h"
#endif