Skip to content
Permalink
Browse files

added find_main_arena.sh

  • Loading branch information...
pdkl95 committed Mar 14, 2019
1 parent 1122b81 commit 40d856d0de369e0b4d995b32eddd00c40a7aff08
Showing with 36 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +6 −1 Makefile
  3. +29 −0 find_main_arena.sh
@@ -1 +1,2 @@
libptmallocdump.so
glibc_main_arena_address
@@ -7,7 +7,9 @@ RM = rm -f
DUMPER_SRC = ptmallocdump.c
DUMPER_LIB = libptmallocdump.so

TARGETS = $(DUMPER_LIB)
GLIBC_MAIN_ARENA_CACHE = glibc_main_arena_address

TARGETS = $(DUMPER_LIB) $(GLIBC_MAIN_ARENA_CACHE)


all: build
@@ -16,6 +18,9 @@ build: $(TARGETS)
$(DUMPER_LIB): $(DUMPER_SRC)
$(CC) $(CFLAGS) -shared $^ $(LDFLAGS) -o $@

$(GLIBC_MAIN_ARENA_CACHE): $(DUMPER_LIB)
./find_main_arena.sh > $@

clean:
@for file in $(TARGETS) ; do \
if test -f "$$file" ; then \
@@ -0,0 +1,29 @@
#!/bin/sh

DEBUG_FILE_DIR="/usr/lib/debug"

die() {
echo "$0: ERROR - $*" 1>&2
exit 1
}

DUMPER_LIB="$( grep ^DUMPER_LIB Makefile | awk '{ print $3 }' )"
if ! test -f "${DUMPER_LIB}" ; then
die "missing DUMPER_LIB (\"${DUMPER_LIB}\")"
fi

libc_soname_path() {
ldd "${DUMPER_LIB}" |
tr -d '\t' |
grep ^libc.so.6 |
awk '{ print $3 }'
}

real_libc_path="$( readlink -e "$(libc_soname_path)" )"
libc_debug_path="${DEBUG_FILE_DIR}/${real_libc_path}.debug"

if ! test -f "${libc_debug_path}" ; then
die "missing libc debug symbols \"${libc_debug_path}\""
fi

objdump -t "${libc_debug_path}" | grep ' main_arena' | awk '{ print $1 }'

0 comments on commit 40d856d

Please sign in to comment.
You can’t perform that action at this time.