[haiku-commits] haiku: hrev49022 - src/bin src/system/libroot build/jam/packages

  • From: mmlr@xxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 11 Apr 2015 09:41:35 +0200 (CEST)

hrev49022 adds 2 changesets to branch 'master'
old head: 1a704d4de923edbb023059f444490e0313e8f242
new head: 6900f36727a5f664e89d0ebf9812bc4766819078
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=6900f36727a5+%5E1a704d4de923

----------------------------------------------------------------------------

0cf3d62115e3: Make guarded heap accessible through its own libroot_guarded.so.

This adds libroot_guarded.so to the HaikuDevel package. It is the same
as libroot_debug with the debug heap swapped out for the guarded heap.
The guarded heap has some useful features that make it desirable to use
while having the disadvantage of a large memory and address space
overhead which make it unusable in some situations. Therefore the
guarded heap cannot simply replace the debug heap but should still be
made available. As the heap init needs to happen even before having
environment variables, the heap to use can not be chosen dynamically.
Exposing them through their own libraries is the next best thing.

6900f36727a5: Add leak_analyser shell script to analyse guarded heap info.

The script runs the guarded heap allocation output through c++filt to
demangle stack trace symbols and filters out a list of known globals
that are never freed. It also allows to exclude further patterns
provided on the command line.

[ Michael Lotz <mmlr@xxxxxxxx> ]

----------------------------------------------------------------------------

4 files changed, 189 insertions(+), 2 deletions(-)
build/jam/packages/HaikuDevel | 10 +-
src/bin/leak_analyser.sh | 151 ++++++++++++++++++++++
src/system/libroot/Jamfile | 25 ++++
src/system/libroot/posix/malloc_debug/Jamfile | 5 +-

############################################################################

Commit: 0cf3d62115e3f1cce1d0165e603cab3b84e18f2f
URL: http://cgit.haiku-os.org/haiku/commit/?id=0cf3d62115e3
Author: Michael Lotz <mmlr@xxxxxxxx>
Date: Sat Apr 11 07:19:18 2015 UTC

Make guarded heap accessible through its own libroot_guarded.so.

This adds libroot_guarded.so to the HaikuDevel package. It is the same
as libroot_debug with the debug heap swapped out for the guarded heap.
The guarded heap has some useful features that make it desirable to use
while having the disadvantage of a large memory and address space
overhead which make it unusable in some situations. Therefore the
guarded heap cannot simply replace the debug heap but should still be
made available. As the heap init needs to happen even before having
environment variables, the heap to use can not be chosen dynamically.
Exposing them through their own libraries is the next best thing.

----------------------------------------------------------------------------

diff --git a/build/jam/packages/HaikuDevel b/build/jam/packages/HaikuDevel
index b0889aa..c15e872 100644
--- a/build/jam/packages/HaikuDevel
+++ b/build/jam/packages/HaikuDevel
@@ -19,7 +19,11 @@ AddFilesToPackage develop lib :
AddFilesToPackage develop lib : kernel.so : _KERNEL_ ;

# additional libraries
-local developmentLibs = <revisioned>libroot_debug.so ;
+local developmentLibs =
+ <revisioned>libroot_debug.so
+ <revisioned>libroot_guarded.so
+ ;
+
AddFilesToPackage lib : $(developmentLibs) ;

# library symlinks
diff --git a/src/system/libroot/Jamfile b/src/system/libroot/Jamfile
index f3e7d52..5d95fc5 100644
--- a/src/system/libroot/Jamfile
+++ b/src/system/libroot/Jamfile
@@ -62,6 +62,11 @@ for architectureObject in [ MultiArchSubDirSetup ] {
;
librootDebugObjects = $(librootDebugObjects:G=$(architecture)) ;

+ local librootGuardedObjects =
+ posix_malloc_guarded.o
+ ;
+ librootGuardedObjects =
$(librootGuardedObjects:G=$(architecture)) ;
+
local librootNoDebugObjects =
posix_malloc.o
;
@@ -69,12 +74,15 @@ for architectureObject in [ MultiArchSubDirSetup ] {

local libroot = [ MultiArchDefaultGristFiles libroot.so ] ;
local librootDebug = $(libroot:B=libroot_debug) ;
+ local librootGuarded = $(libroot:B=libroot_guarded) ;

DONT_LINK_AGAINST_LIBROOT on $(libroot) = true ;
DONT_LINK_AGAINST_LIBROOT on $(librootDebug) = true ;
+ DONT_LINK_AGAINST_LIBROOT on $(librootGuarded) = true ;

SetVersionScript $(libroot) : libroot_versions ;
SetVersionScript $(librootDebug) : libroot_versions ;
+ SetVersionScript $(librootGuarded) : libroot_versions ;

SharedLibrary $(libroot)
:
@@ -100,6 +108,17 @@ for architectureObject in [ MultiArchSubDirSetup ] {
[ TargetLibgcc ]
;

+ HAIKU_SONAME on $(librootGuarded) = libroot.so ;
+
+ SharedLibrary $(librootGuarded)
+ :
+ libroot_init.c
+ :
+ $(librootObjects)
+ $(librootGuardedObjects)
+ [ TargetStaticLibsupc++ ]
+ [ TargetLibgcc ]
+ ;

# Copy libroot.so and update the copy's revision section. We
link
# everything against the original, but the copy will end up on
the disk
@@ -112,12 +131,18 @@ for architectureObject in [ MultiArchSubDirSetup ] {
libroot.so : revisioned ] ;
local revisionedLibrootDebug
= $(librootDebug:G=$(revisionedLibroot:G)) ;
+ local revisionedLibrootGuarded
+ = $(librootGuarded:G=$(revisionedLibroot:G)) ;

MakeLocate $(revisionedLibroot) : $(targetDir) ;
CopySetHaikuRevision $(revisionedLibroot) : $(libroot) ;

MakeLocate $(revisionedLibrootDebug) : $(targetDir) ;
CopySetHaikuRevision $(revisionedLibrootDebug) :
$(librootDebug) ;
+
+ MakeLocate $(revisionedLibrootGuarded) : $(targetDir) ;
+ CopySetHaikuRevision $(revisionedLibrootGuarded)
+ : $(librootGuarded) ;
}
}
}
diff --git a/src/system/libroot/posix/malloc_debug/Jamfile
b/src/system/libroot/posix/malloc_debug/Jamfile
index 903167d..ef1d3f3 100644
--- a/src/system/libroot/posix/malloc_debug/Jamfile
+++ b/src/system/libroot/posix/malloc_debug/Jamfile
@@ -14,8 +14,11 @@ for architectureObject in [ MultiArchSubDirSetup ] {
UsePrivateSystemHeaders ;

MergeObject <$(architecture)>posix_malloc_debug.o :
- #guarded_heap.cpp
heap.cpp
;
+
+ MergeObject <$(architecture)>posix_malloc_guarded.o :
+ guarded_heap.cpp
+ ;
}
}

############################################################################

Revision: hrev49022
Commit: 6900f36727a5f664e89d0ebf9812bc4766819078
URL: http://cgit.haiku-os.org/haiku/commit/?id=6900f36727a5
Author: Michael Lotz <mmlr@xxxxxxxx>
Date: Sat Apr 11 07:24:09 2015 UTC

Add leak_analyser shell script to analyse guarded heap info.

The script runs the guarded heap allocation output through c++filt to
demangle stack trace symbols and filters out a list of known globals
that are never freed. It also allows to exclude further patterns
provided on the command line.

----------------------------------------------------------------------------

diff --git a/build/jam/packages/HaikuDevel b/build/jam/packages/HaikuDevel
index c15e872..b18f7d8 100644
--- a/build/jam/packages/HaikuDevel
+++ b/build/jam/packages/HaikuDevel
@@ -82,4 +82,8 @@ if $(HAIKU_GCC_VERSION_$(architecture)[1]) = 2 {
AddSymlinkToPackage data deskbar menu Applications
: ../../../../apps/Debugger : Debugger ;

+# Debugging tools
+SEARCH on leak_analyser.sh = [ FDirName $(HAIKU_TOP) src bin ] ;
+AddFilesToPackage bin : leak_analyser.sh ;
+
BuildHaikuPackage $(haikuDevelPackage) : haiku_devel ;
diff --git a/src/bin/leak_analyser.sh b/src/bin/leak_analyser.sh
new file mode 100755
index 0000000..222388e
--- /dev/null
+++ b/src/bin/leak_analyser.sh
@@ -0,0 +1,151 @@
+#!/bin/bash
+
+if [ ! -f "$1" ]
+then
+ cat << EOF
+
+ $(basename $0) <leaksFile> [<options>] [<excludePatterns>]
+
+ <leaksFile>
+
+ A file containing the allocations with stack traces from
+ the guarded heap output.
+
+ To generate such a file run a program with the following
+ environment variables prefixed and pipe the output to a file:
+
+ LD_PRELOAD=libroot_guarded.so MALLOC_DEBUG=es50 program > file
+
+ The number after the "s" is the stack trace depth. Note that
+ there is an implementation defined maximum.
+
+ --no-default-excludes
+
+ Do not exclude known statics and globals. By default a list of
+ excludes is used that removes known allocations that are never
+ freed by the system libraries.
+
+ --no-exclude-empty
+
+ Do not exclude allocations with no stack trace. By default
+ allocations without a stack trace are excluded. This should
+ only happen for very early allocations where the stack trace
+ setting has not yet been applied. The program should not be
+ able to generate such allocations.
+
+ <excludePatterns>
+
+ Exclude allocations that match a regular expression. The
+ expression is matched against the whole text block of the
+ allocation, so can match in the header line as well as any
+ stack trace lines. Note that the whole block is on a single
+ line and newlines have been replaced with the caret (^)
+ character.
+
+ Multiple exclude patterns can be specified as one argument each
+ and they will be ored to form the final expression.
+
+EOF
+
+ exit 1
+fi
+
+
+FILENAME="$1"
+shift
+
+
+DONE_PARSING_OPTIONS=
+NO_DEFAULTS=
+NO_EXCLUDE_EMPTY=
+while [ -z "$DONE_PARSING_OPTIONS" ]
+do
+ case "$1" in
+ --no-default-excludes)
+ NO_DEFAULTS=yes
+ shift
+ ;;
+ --no-exclude-empty)
+ NO_EXCLUDE_EMPTY=yes
+ shift
+ ;;
+ --*)
+ echo "unrecognized option \"$1\" ignored"
+ shift
+ ;;
+ *)
+ DONE_PARSING_OPTIONS=yes
+ ;;
+ esac
+done
+
+
+function append_pattern {
+ if [ -z "$EXCLUDE_PATTERN" ]
+ then
+ EXCLUDE_PATTERN="$1"
+ else
+ EXCLUDE_PATTERN="$EXCLUDE_PATTERN|$1"
+ fi
+}
+
+
+EXCLUDE_PATTERN=""
+if [ -z "$NO_DEFAULTS" ]
+then
+ declare -a DEFAULT_EXCLUDE_LIST=( \
+ "<libroot.so> __cxa_atexit " \
+ "<libroot.so> BPrivate::Libroot::LocaleBackend::LoadBackend" \
+ "<libbe.so> initialize_before " \
+ "<libbe.so> initialize_after " \
+ "<libbe.so> _control_input_server_" \
+ "<libbe.so> BApplication::_InitGUIContext" \
+ "<libbe.so> BApplication::_InitAppResources" \
+ "<libbe.so> BResources::LoadResource" \
+ "<libbe.so> BClipboard::_DownloadFromSystem" \
+ "<libbe.so> BToolTipManager::_InitSingleton" \
+ "<libbe.so> BPrivate::WidthBuffer::StringWidth" \
+ "<libtracker.so> _init " \
+ "<libtranslation.so> BTranslatorRoster::Default" \
+ "Translator> " \
+ "<libicui18n.so.54> icu::" \
+ "<libicuuc.so.54> icu::" \
+ )
+
+ for EXCLUDE in "${DEFAULT_EXCLUDE_LIST[@]}"
+ do
+ append_pattern "$EXCLUDE"
+ done
+fi
+
+
+if [ -z "$NO_EXCLUDE_EMPTY" ]
+then
+ append_pattern "^[^^]*\^$"
+fi
+
+
+while [ $# -gt 0 ]
+do
+ append_pattern "$1"
+ shift
+done
+
+
+ALLOCATIONS=$(cat "$FILENAME" | egrep "^allocation: |^ " | tr '\n' '^' \
+ | sed 's/\^a/~a/g' | tr '~' '\n' | sed 's/$/^/' | c++filt)
+
+if [ ! -z "$EXCLUDE_PATTERN" ]
+then
+ ALLOCATIONS=$(echo "$ALLOCATIONS" | egrep -v "$EXCLUDE_PATTERN")
+fi
+
+if [ -z "$ALLOCATIONS" ]
+then
+ COUNT=0
+else
+ COUNT=$(echo "$ALLOCATIONS" | wc -l)
+fi
+
+
+echo "$ALLOCATIONS^total leaks: $COUNT" | tr '^' '\n' | less


Other related posts: