From 2c534d50ae0d9d7ba0619ff8af90d4d269175ea3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 20 Sep 2009 18:52:27 +0200 Subject: optionally read debug info for backtraces --- Makefile.am | 19 ++++++++++++++++++- README | 34 +++++++++++++++++++++++++++++++++- configure.ac | 3 +++ matrace.c | 6 ++++++ matrace.in | 14 +++++++++++++- mutrace.c | 6 ++++++ mutrace.in | 18 +++++++++++++++--- 7 files changed, 94 insertions(+), 6 deletions(-) diff --git a/Makefile.am b/Makefile.am index e8f4c94..703f610 100644 --- a/Makefile.am +++ b/Makefile.am @@ -27,7 +27,8 @@ EXTRA_DIST = \ lib_LTLIBRARIES = \ libmutrace.la \ - libmatrace.la + libmatrace.la \ + libmutrace-backtrace-symbols.la bin_SCRIPTS = \ mutrace \ @@ -69,6 +70,21 @@ libmatrace_la_CFLAGS = \ $(PTHREAD_CFLAGS) \ -DSONAME=\"libmatrace.so\" +libmutrace_backtrace_symbols_la_SOURCES = \ + backtrace-symbols.c +libmutrace_backtrace_symbols_la_LDFLAGS = \ + -avoid-version \ + -module \ + -export-dynamic \ + -shared \ + -prefer-pic +libmutrace_backtrace_symbols_la_LIBADD = \ + $(PTHREAD_LIBS) \ + -lrt \ + -ldl +libmutrace_backtrace_symbols_la_CFLAGS = \ + $(PTHREAD_CFLAGS) + mutrace: mutrace.in Makefile sed -e 's,@PACKAGE_STRING\@,$(PACKAGE_STRING),g' \ -e 's,@PACKAGE_NAME\@,$(PACKAGE_NAME),g' < $< > $@ @@ -82,5 +98,6 @@ matrace: matrace.in Makefile install-exec-hook: rm -f $(DESTDIR)$(libdir)/libmutrace.la rm -f $(DESTDIR)$(libdir)/libmatrace.la + rm -f $(DESTDIR)$(libdir)/libmutrace-backtrace-symbols.la ACLOCAL_AMFLAGS = -I m4 diff --git a/README b/README index 6a311b2..5195524 100644 --- a/README +++ b/README @@ -7,14 +7,46 @@ GITWEB: http://git.0pointer.de/?p=mutrace.git NOTES: - For a terse overview wht mutrace can do for you, please read + For a terse overview what mutrace can do for you, please read the announcement blog story: http://0pointer.de/blog/projects/mutrace.html + The tarball includes two profilers: + + mutrace profiles lock contention for you. Just use it as + prefix for your usual command line and it will profile + mutexes used in all child processes. Example: + + mutrace gedit + + matrace traces memory allocation operations in realtime + threads for you. It is of no use in applications that do not + make use of realtime scheduling. Example: + + matrace myrealtimetool + + Both tools understand a --debug-info switch in which case the + backtraces generated will include debugging information such as + line numbers and source file names. This is not enabled by + default since generating those traces is not always safe in + situations where locks are taken or memory allocated as we do + it here. YMMV. + + mutrace cannot be used to profile glibc-internal mutexes. + LICENSE: LGPLv3+ + Exception: + + backtrace-symbols.c is GPLv2+. Which probably means that using + the --debug-info switch for mutrace and matrace might not be + legally safe for non-GPL-compatible applications. However, + since that module is independantly built into a seperate .so + it should still be safe using the profilers without this + switch on such software. + AUTHORS: Lennart Poettering diff --git a/configure.ac b/configure.ac index 551143c..ccfc514 100644 --- a/configure.ac +++ b/configure.ac @@ -72,6 +72,9 @@ AC_CHECK_HEADERS([sys/poll.h]) AC_CHECK_HEADERS([sys/ioctl.h]) AC_CHECK_HEADERS([byteswap.h]) +AC_SEARCH_LIBS([bfd_init], [bfd], [], [AC_MSG_ERROR([*** libbfd not found])]) +AC_CHECK_HEADERS([bfd.h], [], [AC_MSG_ERROR([*** POSIX caps headers not found])]) + #### Typdefs, structures, etc. #### AC_C_CONST diff --git a/matrace.c b/matrace.c index ddee2e2..e2183a2 100644 --- a/matrace.c +++ b/matrace.c @@ -248,12 +248,18 @@ static bool is_realtime(void) { static bool verify_frame(const char *s) { + /* Generated by glibc's native backtrace_symbols() on Fedora */ if (strstr(s, "/" SONAME "(")) return false; + /* Generated by glibc's native backtrace_symbols() on Debian */ if (strstr(s, "/" SONAME " [")) return false; + /* Generated by backtrace-symbols.c */ + if (strstr(s, __FILE__":")) + return false; + return true; } diff --git a/matrace.in b/matrace.in index 7d4d8c6..7ab078f 100755 --- a/matrace.in +++ b/matrace.in @@ -17,12 +17,14 @@ # You should have received a copy of the GNU Lesser General Public # License along with mutrace. If not, see . -if ! TEMP=`getopt -o +h --long frames:,help -n matrace -- "$@"` ; then +if ! TEMP=`getopt -o +dh --long frames:,debug-info,help -n matrace -- "$@"` ; then exit 1 fi eval set -- "$TEMP" +debug_info=0 + while : ; do case $1 in --frames) @@ -30,6 +32,11 @@ while : ; do shift 2 ;; + -d|--debug-info) + debug_info=1 + shift 1 + ;; + -h|--help) cat <. -if ! TEMP=`getopt -o +arh --long hash-size:,frames:,locked-min:,owner-changed-min:,contended-min:,max:,trap,help,all -n mutrace -- "$@"` ; then +if ! TEMP=`getopt -o +ardh --long hash-size:,frames:,locked-min:,owner-changed-min:,contended-min:,max:,trap,help,all,debug-info -n mutrace -- "$@"` ; then exit 1 fi eval set -- "$TEMP" +debug_info=0 + while : ; do case $1 in --hash-size) @@ -65,6 +67,11 @@ while : ; do shift 1 ;; + -d|--debug-info) + debug_info=1 + shift 1 + ;; + -a|--all) export MUTRACE_LOCKED_MIN=0 export MUTRACE_OWNER_CHANGED_MIN=0 @@ -77,7 +84,7 @@ while : ; do cat <