summaryrefslogtreecommitdiff
path: root/test/backtrace
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2010-08-17 17:10:46 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2010-08-17 17:11:49 +0200
commitff4679178975cede4a4173bcf03447f1c0058d73 (patch)
treed99d039631a372b50cdc6f797a3dd4e6369511f1 /test/backtrace
parent5f06e7b159df42ceafafe9a7266148f658a91fad (diff)
downloadconnman-ff4679178975cede4a4173bcf03447f1c0058d73.tar.gz
connman-ff4679178975cede4a4173bcf03447f1c0058d73.tar.bz2
connman-ff4679178975cede4a4173bcf03447f1c0058d73.zip
ConnMan backtrace support
Add a generic signal handler in order to dump ConnMan backtrace when crashing. The implementation is based on glibc backtrace() routines and thus can not resolve static function names. A little python wrapper over addr2line fixes that by taking a full backtrace from a complete connman log file.
Diffstat (limited to 'test/backtrace')
-rw-r--r--test/backtrace55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/backtrace b/test/backtrace
new file mode 100644
index 00000000..d33bcb18
--- /dev/null
+++ b/test/backtrace
@@ -0,0 +1,55 @@
+#!/usr/bin/python
+
+import os
+import re
+import sys
+import subprocess
+
+if (len(sys.argv) < 3):
+ print "Usage: %s [connman binary] [connman log]" % (sys.argv[0])
+ sys.exit(1)
+
+binary = sys.argv[1]
+count = 0
+frames = []
+addrs = []
+
+log_file = open(sys.argv[2], 'r')
+
+# Extract addresses
+for line in log_file:
+ matchobj = re.compile(r'\[(0x[0-9a-f]+)\]$').search(line)
+ if matchobj:
+ addrs.append(matchobj.group(1))
+
+log_file.close()
+
+# Feed into addr2line
+command = ['addr2line', '--demangle', '--functions', '--basename', '-e', binary]
+command.extend(addrs)
+
+p = subprocess.Popen(command, shell=False, bufsize=0,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)
+(child_stdin, child_stdout) = (p.stdin, p.stdout)
+
+child_stdin.close()
+
+# Backtrace display
+for line in child_stdout:
+
+ if line.startswith("??"): continue
+
+ line = line.strip()
+
+ frames.append(line)
+
+child_stdout.close()
+
+frame_count = len(frames);
+
+count = 0
+print "-------- ConnMan backtrace --------"
+while count < frame_count:
+ print "[%d]: %s() [%s]" % (count/2, frames[count], frames[count + 1])
+ count = count + 2
+print "-----------------------------------"