LLDB: NetBSD Process Plugin enhancements
Last month I have worked on features of the Process Plugin on NetBSD and support for threads in core(5) files.
I've managed to achieve the following accomplishments:
This allows to:
There are equivalent operations in FreeBSD with the same names.
This code was prepared by Nick Hudson and it was used in ATF tests to verify behavior of software breakpoints.
Add new defines in sysctl(2) on amd64 and i386 ports. These values are defined in <x86/cpu.h>:
int: FPU Instructions layout * to use this, CPU_OSFXSR must be true * 0: FSAVE * 1: FXSAVE * 2: XSAVE * 3: XSAVEOPT
int: FPU Instruction layout size
quad: FPU XSAVE features
These values are useful to get FPU (floating point unit) properties in e.g. a debugger. This information is required to properly implement FPR (floating point register) tracer operations on x86 processors.
Few mistakes were corrected to make the documentation more correct.
There were added new tests for new ptrace(2) operations (PT_SETSTEP and PT_CLEARSTEP).
Also several tests were updated to reflect the current state of "successfully passed" and "expected failure". This is important to mark issues that are already known and quickly catch new regressions in future changes.
It was decided that NetBSD will not introduce new fcntl(2) function for compatibility with certain other systems. This means that once LLDB will require this feature, we will need to introduce a workaround in the project.
The NetBSD Process Plugin in LLDB acquired new capabilities. Additionally enhancements in LLDB were developed such as handling threads in core(5) files.
The x86_64 architecture supports in default properties FXSAVE processor instructions. The FXSAVE feature allows to operate over floating point registers. A thread state (context) is composed of (and not restricted to) general and floating point registers.
The NetBSD Process Plugin acquired the functionality to read these registers and optionally set new values for them.
A programer can use hardware assisted watchpoints to stop execution of a tracee whenever a certain variable or instruction was read/written/executed. The support for this feature has been implemented on NetBSD with ptrace(2) operations PT_SETDBREGS and PT_GETDBREGS. These operations are now available in the LLDB Process plugin.
I've included support for LWPs in core(5) files. This means that larger programs with threads, like Firefox that emitted coredump for some reason (usually during crash) can be investigated postmortem.
I've prepared a recording with the script(1) utility from the NetBSD base system. To replay it:
script -p ./firefox-core.typescript
This recording shows a debugging session of a Firefox core(5) file.
(I was kind to prepare a Linux version of the NetBSD script(1) here).
The plan for the next milestone is continuing development of threads in the NetBSD Process Plugin. I will need to work more on correctness of ptrace(2) calls as new issues were detected in setups with threads that resulted in crashes.
There is also ongoing work on a new build node running NetBSD-current (prerelease of 8) and building LLVM+Clang+LLDB. I'm working on enabling unit tests to catch functional reqressions quickly. The original LLDB node cluster was privately funded by myself in the last two years and has been switched to a machine hosted by The NetBSD Foundation.
To keep this machine up and running (8 CPU, 24 GB RAM) community support through donations is required. This is crucial to actively maintain the LLVM toolchain (Clang, LLDB and others) on NetBSD.
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: