Pesticide

From Wiki

Jump to: navigation, search
  • Debugging: Interposing shared library using LD_PRELOAD link
  • Debugging: Backtrace (1. backtrace(), 2. spawn GDB process) [gbacktrace.c in glib]
  • Debugging: Breakpoint, ptrace (using SIGTRAP or int 3) ptrace1 ptrace2
  • Memory Debugging: glibc support (mtrace, MALLOC_TRACE, etc)
  • Memory Debugging: valgrind
  • Memory Debugging: DUMA (formerly known as efence)

Memory function


메모리 디버깅 메모리 할당 원리 (malloc/free)


Library Interposing

공유 라이브러리 끼워넣기

GDB 사용법

Using ptrace system call GDB breakpoint strace ltrace

DUMA(Electric Fence) 사용법 mmap, mprotect

pseudo obstack

valgrind 사용법

SIGSEGV 발생시 sigaction, ucontext, sigaltstack을 써서 register 값 덤프 후 죽게 만듬. 그리고 코드에 디버깅 정보가 없음. stack을 역추적해서 /proc/PID/maps에 있는 shared symbol 제외 후, SIGSEGV가 발생한 user function 찾기.

/bin/sh
 
program_name=`basename $0`
if test $# -lt 2; then
    cat 1>&2 <<EOF
Return the file that is mapped at given address
Usage: $program_name PID ADDRESS...
EOF
    exit 1
fi
 
pid="$1"
shift 1
 
for f in "$@"; do
    mapfile="/proc/$pid/maps"
    if test ! -r "$mapfile"; then
        echo "error: cannot access $mapfile" 1>&2
        exit 1
    fi
 
    cat "$mapfile" | awk "{
    where = match(\$1, \"([0-9a-fA-F]+)-([0-9a-fA-F]+)\", m);
 
    if (where != 0) {
        beg = strtonum(sprintf(\"0x%s\", m[1]));
        end = strtonum(sprintf(\"0x%s\", m[2]));
        ptr = strtonum(sprintf(\"0x%s\", \"$f\"));
 
        if (ptr >= beg && ptr < end) {
            printf(\"[%08x] %08x %s\n\", beg, ptr - beg, \$6)
        }
    }
}"
 
done

knowhow

1. embedded system에서 multi-threaded app에서 특정 thread가 실행되지 않은 버그(TV epg update thread) -- 알고봤더니 다른 thread들의 priority가 높아서, 해당 thread가 starvation을 일으킨 것이었음.

 알고봤더니,
Personal tools