From e2ed6fbeb18cba1235c6a260b754f11ecc9d4cb0 Mon Sep 17 00:00:00 2001 From: William Tu Date: Fri, 27 Sep 2019 10:22:55 -0700 Subject: fatal-signal: Catch SIGSEGV and print backtrace. The patch catches the SIGSEGV signal and prints the backtrace using libunwind at the monitor daemon. This makes debugging easier when there is no debug symbol package or gdb installed on production systems. The patch works when the ovs-vswitchd compiles even without debug symbol (no -g option), because the object files still have function symbols. For example: |daemon_unix(monitor)|WARN|SIGSEGV detected, backtrace: |daemon_unix(monitor)|WARN|0x0000000000482752 |daemon_unix(monitor)|WARN|0x00007fb4900734b0 |daemon_unix(monitor)|WARN|0x00007fb49013974d <__poll+0x2d> |daemon_unix(monitor)|WARN|0x000000000052b348 |daemon_unix(monitor)|WARN|0x00000000005153ec |daemon_unix(monitor)|WARN|0x000000000058630a |daemon_unix(monitor)|WARN|0x00000000004ffd1d |daemon_unix(monitor)|WARN|0x00007fb490b3b6ba |daemon_unix(monitor)|WARN|0x00007fb49014541d |daemon_unix(monitor)|ERR|1 crashes: pid 122849 died, killed \ (Segmentation fault), core dumped, restarting However, if the object files' symbols are stripped, then we can only get init function plus offset value. This is still useful when trying to see if two bugs have the same root cause, Example: |daemon_unix(monitor)|WARN|SIGSEGV detected, backtrace: |daemon_unix(monitor)|WARN|0x0000000000482752 <_init+0x7d68a> |daemon_unix(monitor)|WARN|0x00007f5f7c8cf4b0 |daemon_unix(monitor)|WARN|0x00007f5f7c99574d <__poll+0x2d> |daemon_unix(monitor)|WARN|0x000000000052b348 <_init+0x126280> |daemon_unix(monitor)|WARN|0x00000000005153ec <_init+0x110324> |daemon_unix(monitor)|WARN|0x0000000000407439 <_init+0x2371> |daemon_unix(monitor)|WARN|0x00007f5f7c8ba830 <__libc_start_main+0xf0> |daemon_unix(monitor)|WARN|0x0000000000408329 <_init+0x3261> |daemon_unix(monitor)|ERR|1 crashes: pid 106155 died, killed \ (Segmentation fault), core dumped, restarting Most C library functions are not async-signal-safe, meaning that it is not safe to call them from a signal handler, for example printf() or fflush(). To be async-signal-safe, the handler only collects the stack info using libunwind, which is signal-safe, and issues 'write' to the pipe, where the monitor thread reads and prints to ovs-vswitchd.log. Tested-at: https://travis-ci.org/williamtu/ovs-travis/builds/590503433 Signed-off-by: William Tu Signed-off-by: Ben Pfaff --- .travis.yml | 1 + 1 file changed, 1 insertion(+) (limited to '.travis.yml') diff --git a/.travis.yml b/.travis.yml index 68026312b..b547eb041 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,7 @@ addons: - selinux-policy-dev - libunbound-dev - libunbound-dev:i386 + - libunwind-dev before_install: ./.travis/${TRAVIS_OS_NAME}-prepare.sh -- cgit v1.2.1