diff options
author | Clifford Wolf <clifford@clifford.at> | 2014-12-29 13:33:33 +0100 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2014-12-29 13:33:33 +0100 |
commit | ecd64182c5a3689ef293bccf032e1d7eecada91a (patch) | |
tree | 5f3d2043112291b43a0583c3fd95590cd68b4b60 /kernel/log.cc | |
parent | 3ff0d04555c4467a2d9bcd5e754d82ede5bf84dd (diff) | |
download | yosys-ecd64182c5a3689ef293bccf032e1d7eecada91a.tar.gz yosys-ecd64182c5a3689ef293bccf032e1d7eecada91a.tar.bz2 yosys-ecd64182c5a3689ef293bccf032e1d7eecada91a.zip |
Added "yosys -X"
Diffstat (limited to 'kernel/log.cc')
-rw-r--r-- | kernel/log.cc | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/kernel/log.cc b/kernel/log.cc index 5b18e3d6c..b984f0112 100644 --- a/kernel/log.cc +++ b/kernel/log.cc @@ -25,6 +25,10 @@ # include <sys/time.h> #endif +#ifdef __linux__ +# include <dlfcn.h> +#endif + #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -243,6 +247,97 @@ void log_pop() log_flush(); } +void log_backtrace(const char *prefix, int levels) +{ +#ifdef __linux__ + if (levels <= 0) return; + + Dl_info dli; + void *p; + + if ((p = __builtin_extract_return_addr(__builtin_return_address(0))) && dladdr(p, &dli)) { + log("%sframe #1: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr); + } else { + log("%sframe #1: ---\n", prefix); + return; + } + + if (levels <= 1) return; + + if ((p = __builtin_extract_return_addr(__builtin_return_address(1))) && dladdr(p, &dli)) { + log("%sframe #2: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr); + } else { + log("%sframe #2: ---\n", prefix); + return; + } + + if (levels <= 2) return; + + if ((p = __builtin_extract_return_addr(__builtin_return_address(2))) && dladdr(p, &dli)) { + log("%sframe #3: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr); + } else { + log("%sframe #3: ---\n", prefix); + return; + } + + if (levels <= 3) return; + + if ((p = __builtin_extract_return_addr(__builtin_return_address(3))) && dladdr(p, &dli)) { + log("%sframe #4: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr); + } else { + log("%sframe #4: ---\n", prefix); + return; + } + + if (levels <= 4) return; + + if ((p = __builtin_extract_return_addr(__builtin_return_address(4))) && dladdr(p, &dli)) { + log("%sframe #5: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr); + } else { + log("%sframe #5: ---\n", prefix); + return; + } + + if (levels <= 5) return; + + if ((p = __builtin_extract_return_addr(__builtin_return_address(5))) && dladdr(p, &dli)) { + log("%sframe #6: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr); + } else { + log("%sframe #6: ---\n", prefix); + return; + } + + if (levels <= 6) return; + + if ((p = __builtin_extract_return_addr(__builtin_return_address(6))) && dladdr(p, &dli)) { + log("%sframe #7: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr); + } else { + log("%sframe #7: ---\n", prefix); + return; + } + + if (levels <= 7) return; + + if ((p = __builtin_extract_return_addr(__builtin_return_address(7))) && dladdr(p, &dli)) { + log("%sframe #8: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr); + } else { + log("%sframe #8: ---\n", prefix); + return; + } + + if (levels <= 8) return; + + if ((p = __builtin_extract_return_addr(__builtin_return_address(8))) && dladdr(p, &dli)) { + log("%sframe #9: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr); + } else { + log("%sframe #9: ---\n", prefix); + return; + } + + if (levels <= 9) return; +#endif +} + void log_reset_stack() { while (header_count.size() > 1) |