March 01, 2017 posted by Kamil Rytarowski
During this month I've finished the needed work in the base distribution in order to host fully featured LLDB.
Currently the ptrace
(2) interfaces in NetBSD are, in terms of features, closely related to FreeBSD and Linux.
There are only few bugs left with filed Problem Reports and alerting regression tests,
however they do not interfere with the needed functions to move the port of the debugger forward.
This time I will shortly iterate over the finished tasks as I would like to present slides on ptrace(2) in NetBSD.
As usual hundreds of ATF tests were introduced, few Problem Reports filed and two patches upstreamed to LLDB.
What has been done in NetBSD
I've managed to achieve the following goals:
- Marked exect(3) obsolete in libc
- Removed libpthread_dbg(3) from the base distribution
- Added new ptrace(2) operations PT_SET_SIGMASK and PT_GET_SIGMASK
- Switch ptrace(2) PT_WATCHPOINT API to PT_GETDBRGS and PT_SETDBREGS
- Validation of ptrace(2) PT_SYSCALL
The exect(3) interface is no longer functional and it's the proper time to obsolete it.
The libpthread_dbg(3) library is no longer needed, it became unnecessary along with the M:N thread model removal.
I originally added the PT_*ET_SIGMASK interface in order to help the criu port for NetBSD.
This software is used to checkpoint programs on Linux.
Debuggers can also have checkpointing support, for example GDB/Linux has this ability.
The debug registers are finally in the proper form on NetBSD.
The previous API had defects as it was designed to be safe, but keeping it safe on the kernel side was impractical.
I've finally decided to adapt it to the existing FreeBSD semantics and reuse PT_*ETDBREGS operations.
I've verified this new API on real hardware amd64 (Intel i7) and i386 (Intel Pentium IV) with newly written 390 tests.
It's worth noting that this API renders GDB to support hardware watchpoints on NetBSD almost out-of-the-box!
However it's not free of bugs, after catching a watchpoint, GDB enters on a trap in a dynamic linker (?).
Watchpoint 2: traceme
Old value = 0
New value = 16
main (argc=1, argv=0x7f7fff79fe30) at test.c:8
8 printf("traceme=%d\n", traceme);
Watchpoint 2 deleted because the program has left the block in
which its expression is valid.
0x00007f7e3c000782 in _rtld_bind_start () from /usr/libexec/ld.elf_so
Program received signal SIGTRAP, Trace/breakpoint trap.
0x00007f7e3c0007b5 in _rtld_bind_start () from /usr/libexec/ld.elf_so
[Inferior 1 (process 28797) exited normally]
Sadly the PT_SYSCALL needs more work.
The current implementation is currently broken and cannot stop the process on syscall entry.
What has been done in LLDB
As usual, I've pushed some ready patches to upstream LLDB.
The first one covers Debug Register accessors and the second one adds proper thread identity detection on NetBSD.
Porting ptrace(2) software to NetBSD
I have prepared this presentation to illustrate the new code in the context of Linux and other BSDs.
To browse the slides one must use arrow buttons or the mouse scroll wheel. Press the h key for help.
Porting ptrace(2) software to NetBSD.
This work was sponsored by The NetBSD Foundation.
The NetBSD Foundation is a non-profit organization and welcomes any donations to help us continue funding projects and services to the open-source community. Please consider visiting the following URL, and chip in what you can: