descriptionnone
repository URLhttps://github.com/rofl0r/debuglib.git
ownerretnyg@gmx.net
last changeWed, 6 Apr 2022 22:08:20 +0000 (6 22:08 +0000)
last refreshSat, 27 Apr 2024 11:32:48 +0000 (27 13:32 +0200)
content tags
add:
README.md

debuglib - a convenience wrapper around ptrace

this library tries to abstract away arch-specific differences for ptrace(), and provide a neater, consistent high-level interface.

it was written with the idea of writing a custom ncurses debugger without having to remote-control gdb. using the provided primitives it is quite easy to write an asm-level debugger like ollydbg, but for a source- based debugger like gdb it is required to deal with the different DWARF formats, which are quite complicated.

the API is unstable at this moment. there are working examples for a debugger and syscall hooks in the tests/ directory.

debuglib was designed for use with the RcB2 build tool, and depends on my multi-purpose C library libulz, which provides some data structures such as hashmaps and lists.

How to build the filetracer example program

    cd /tmp
    mkdir debuglib-0000
    cd debuglib-0000/
    git clone https://github.com/rofl0r/debuglib
    git clone https://github.com/rofl0r/libulz lib
    git clone https://github.com/rofl0r/rcb2
    export PATH=$PATH:/tmp/debuglib-0000/rcb2
    ln -s /tmp/debuglib-0000/rcb2/rcb2.py /tmp/debuglib-0000/rcb2/rcb2
    cd debuglib/tests
    rcb2 filetrace.c

Known bugs:

there are 2 ways to use the ptrace(2) api: the old method is using PTRACE_ATTACH, this is what the library currently uses. it has one major problem, which is the inability to properly deal with SIGSTOP/SIGTSTP received by a child when tracing. therefore a new API was designed that uses PTRACE_SEIZE instead. i was unaware of the issue when designing this library and using the new seize API instead would require a major rewrite, and more costly, re-test of all the functionality. fortunately processes sending SIGSTOP to subprocesses occur quite rarely, so the issue is encountered only in rare cases. the issue can be reproduced by creating a shell script with the content

msgmerge --update -q /dev/null /dev/null

on debian sid i386 at the time of this writing, and then executing

DEBUG=1 idfake sh foo.sh

using the supplied idfake example program. This result in the program hanging forever. the rather well-known program proot is victim to the same design issue. recent versions of strace otoh use the new seize API when available.

shortlog
2022-04-06 rofl0ridfake: improve debug output with syscall return valuemaster
2022-04-06 rofl0ridfake: don't crash if PATH isn't exported
2021-11-21 rofl0rREADME: add paragraph about SIGSTOP issue
2021-11-21 rofl0ridfake: add support for SYS_setxattr
2021-11-21 rofl0ridfake: extend comment
2021-11-21 rofl0ridfake: add support for i386 chown syscall variants
2021-09-13 rofl0ridfake: add yet another chown-related syscall
2021-04-24 rofl0ridfake: add support for fchown and fchownat syscalls
2021-04-24 rofl0rimprove demo debugger
2021-04-24 rofl0radd debugger_continue_signal, pid printing on error...
2021-01-23 rofl0rfix copy/paste error in debugger_detach()
2021-01-21 rofl0radd idfake example
2021-01-21 rofl0radd APIs to get/set syscall return value
2019-07-06 rofl0rfix hardcoded argv in memusage/skeleton
2019-07-06 rofl0rmove examples to examples/
2019-07-06 rofl0radd memusage tool
...
heads
2 years ago master