| 1771 | } |
| 1772 | |
| 1773 | void dumpCodeAroundEIP(void *eip) { |
| 1774 | Dl_info info; |
| 1775 | if (dladdr(eip, &info) != 0) { |
| 1776 | serverLog(LL_WARNING|LL_RAW, |
| 1777 | "\n------ DUMPING CODE AROUND EIP ------\n" |
| 1778 | "Symbol: %s (base: %p)\n" |
| 1779 | "Module: %s (base %p)\n" |
| 1780 | "$ xxd -r -p /tmp/dump.hex /tmp/dump.bin\n" |
| 1781 | "$ objdump --adjust-vma=%p -D -b binary -m i386:x86-64 /tmp/dump.bin\n" |
| 1782 | "------\n", |
| 1783 | info.dli_sname, info.dli_saddr, info.dli_fname, info.dli_fbase, |
| 1784 | info.dli_saddr); |
| 1785 | size_t len = (long)eip - (long)info.dli_saddr; |
| 1786 | unsigned long sz = sysconf(_SC_PAGESIZE); |
| 1787 | if (len < 1<<13) { /* we don't have functions over 8k (verified) */ |
| 1788 | /* Find the address of the next page, which is our "safety" |
| 1789 | * limit when dumping. Then try to dump just 128 bytes more |
| 1790 | * than EIP if there is room, or stop sooner. */ |
| 1791 | void *base = (void *)info.dli_saddr; |
| 1792 | unsigned long next = ((unsigned long)eip + sz) & ~(sz-1); |
| 1793 | unsigned long end = (unsigned long)eip + 128; |
| 1794 | if (end > next) end = next; |
| 1795 | len = end - (unsigned long)base; |
| 1796 | serverLogHexDump(LL_WARNING, "dump of function", |
| 1797 | base, len); |
| 1798 | dumpX86Calls(base, len); |
| 1799 | } |
| 1800 | } |
| 1801 | } |
| 1802 | |
| 1803 | void sigsegvHandler(int sig, siginfo_t *info, void *secret) { |
| 1804 | UNUSED(secret); |
no test coverage detected