MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / dumpCodeAroundEIP

Function dumpCodeAroundEIP

src/debug.cpp:1995–2023  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1993}
1994
1995void dumpCodeAroundEIP(void *eip) {
1996 Dl_info info;
1997 if (dladdr(eip, &info) != 0) {
1998 serverLog(LL_WARNING|LL_RAW,
1999 "\n------ DUMPING CODE AROUND EIP ------\n"
2000 "Symbol: %s (base: %p)\n"
2001 "Module: %s (base %p)\n"
2002 "$ xxd -r -p /tmp/dump.hex /tmp/dump.bin\n"
2003 "$ objdump --adjust-vma=%p -D -b binary -m i386:x86-64 /tmp/dump.bin\n"
2004 "------\n",
2005 info.dli_sname, info.dli_saddr, info.dli_fname, info.dli_fbase,
2006 info.dli_saddr);
2007 size_t len = (long)eip - (long)info.dli_saddr;
2008 unsigned long sz = sysconf(_SC_PAGESIZE);
2009 if (len < 1<<13) { /* we don't have functions over 8k (verified) */
2010 /* Find the address of the next page, which is our "safety"
2011 * limit when dumping. Then try to dump just 128 bytes more
2012 * than EIP if there is room, or stop sooner. */
2013 void *base = (void *)info.dli_saddr;
2014 unsigned long next = ((unsigned long)eip + sz) & ~(sz-1);
2015 unsigned long end = (unsigned long)eip + 128;
2016 if (end > next) end = next;
2017 len = end - (unsigned long)base;
2018 serverLogHexDump(LL_WARNING, "dump of function",
2019 base, len);
2020 dumpX86Calls(base, len);
2021 }
2022 }
2023}
2024
2025void sigsegvHandler(int sig, siginfo_t *info, void *secret) {
2026 UNUSED(secret);

Callers 1

sigsegvHandlerFunction · 0.85

Calls 3

serverLogFunction · 0.85
serverLogHexDumpFunction · 0.85
dumpX86CallsFunction · 0.85

Tested by

no test coverage detected