Crash dumps and observability¶
Crash collection and ELF layout¶
Crash collection operates independently of normal userspace services. In QEMU the kernel emits a bounded serial panic report with CPU registers, kernel and direct-map addresses, and dumpable physical RAM ranges. A host collector freezes the guest and obtains that memory through QMP. A physical machine will need a suitable panic-safe output path. Firmware-reserved and inaccessible areas such as MMIO are excluded as appropriate by the platform’s dumpable-range policy.
Both dump types use ELF core files. The full dump includes all registered
dumpable RAM. The minidump includes kernel image mappings, pages reached
through the faulting and applicable secondary CPU page-table walks,
and selected kernel stack pages. Both emit virtual kernel image mappings
and direct-map aliases through PT_LOAD segments. The corresponding
physical addresses remain in the program headers.
The current collector emits little-endian RV64 ELF. Each included CPU has
a Linux-compatible CORE/NT_PRSTATUS note with PC and x1 through x31
at byte offset 112 in the note payload. The custom System note
(type 0x52435301) carries format version 2, dump kind, direct-map and
kernel image locations, trap state, hart identity, and the SHA-256 of
the kernel ELF. The host collector verifies executable bytes against the
supplied kernel image before writing the core. Preserve explicit register,
endianness, mapping, and symbol-identification rules when adding new
architectures. GDB and LLDB can use the resulting ELF and matching symbols.
-
struct crash_frame_t¶
Trap assembly must describe the interrupted PC and stack, mark an asynchronous entry as a signal frame, and retain its unwind records when debug information is absent. The debugger can then reconstruct the interrupted context and stop at genuine unwind boundaries.
Live kernel debugging¶
QEMU’s existing GDB stub lets GDB and LLDB control the emulated CPUs. Use the matching kernel ELF for source and symbols. To examine a server through the QEMU stub, load its ELF at its mapped addresses and stop an emulated CPU while that server’s address space is active. The CPU view is also useful when investigating kernel entry and exit or a context switch.
On physical hardware, use an external debug probe such as JTAG with OpenOCD where the board exposes and enables it. An external probe can reach early boot and inspect the machine when the kernel cannot run a debug handler. The supported breakpoints, watchpoints, and stepping operations depend on the architecture and board.
Provide an opt-in kernel stub that speaks GDB Remote Serial Protocol through a polled UART or supported firmware debug console. Its code, stack, and buffers must be available without allocations or calls to userspace services. On SMP, coordinate a stop before presenting a consistent machine snapshot and report any CPUs that did not stop. Keep panic capture available if interactive debugging cannot proceed. Give the debug transport exclusive ownership while a session is active so console output cannot corrupt packets.
An operator can connect directly over serial or forward it to TCP from another machine. The forwarding host owns access control. The guest’s ordinary network stack is suitable for live service debugging when it is healthy and independent of the target. Use the out-of-band path for early boot, kernel panics, and network service failures.
Live userspace debugging¶
The supervisor starts the resident debug-agent with a
revocable debug capability for one task instance. The kernel checks it
for thread enumeration, stop and resume, register and memory access, and
debug events. Replacing the target revokes the session and its derived
capabilities. The agent serves the GDB Remote Serial Protocol. The host
debugger uses the matching ELF and load addresses to resolve symbols and
unwind stacks.
The serial agent exposes integer registers and the PC on AMD64, ARM64, PowerPC64 in both byte orders, and RV64. It reports each target’s native register widths and byte order. Register and memory writes require separate authority. Software breakpoints patch only private executable pages, retain the original instruction bytes in the kernel, and synchronize the instruction stream before userspace resumes. AMD64 normalizes the saved post-INT3 PC to the breakpoint address.
A step holds peer threads. AMD64 uses the trap flag, ARM64 uses the EL0 software-step exception, and PowerPC64 uses the trace exception. RV64 uses a temporary breakpoint at the decoded successor. A stepped system call stops at its return boundary. Detach restores patches and releases the debugger stop independently of job control.
The agent starts from resident memory, uses a wired 16 KiB stack and its own scheduled thread, and inspects resident pages without calling the pager. Unmapped memory returns an error. Register writes and stepping require that the selected thread has reached a userspace boundary. The supervisor reserves the polled console for the session and defers health probes that could depend on the stopped service. A debugger stop can block dependent clients. The kernel restores the console and releases stops on detach, agent exit, or the 60-second lease deadline. On a polled UART, a disconnected client is detected by expiry. The supervisor then resumes ordinary health checks. See Service lifecycle and failure.
Use serverctl debug NAME as root on a running RV64 native system.
For a VM server session in a resident image, configure Xmake with
--resident-debug=y. The UEFI and Raspberry Pi boot paths also
accept system.debug-vm on the loader command line. Connect the host
debugger to the serial transport after the ready message.
-
struct debug_registers_t¶
Native integer register snapshot; register numbering is CPU-specific.
Use timestamped fault and IPC tracepoints first for latency-sensitive failures. Stop the target when an investigation needs exact register or memory state and can tolerate delaying dependent clients. The reduced-memory QEMU check reads the stopped VM’s registers and text with 128 MiB of guest RAM, then checks that the VM responds after lease expiry and that the old debug capability cannot read its replacement.
See also
QEMU GDB usage, OpenOCD’s GDB interface, GDB remote connections, LLDB remote debugging, GDB target register features, and seL4 userspace debugging.
Application debugging with ptrace¶
Libc’s FreeBSD-style ptrace() requests go to the process supervisor,
which authorizes one controlling tracer per process. The supervisor uses
the same kernel debug sessions as the resident agent. It confines a
non-root caller to targets with matching real, effective, and saved user
and group IDs and revokes affected sessions on credential changes.
PT_ATTACH stops a running application. With PT_TRACE_ME the
parent receives a stop before the child’s replacement image starts.
waitpid() delivers a debugger stop to the tracer even for a non-child.
Thread-specific breakpoint stops identify the thread through
PT_LWPINFO. The real parent retains its ordinary wait and reaping
relationship. The supervisor clears trace authority and debugger-owned
stops on detach or tracer exit. See Native processes, loading, and the C runtime and Resource domains and branded zones.
debug-remote PROGRAM [ARG ...] launches an application through
ptrace(). debug-remote --attach PID attaches to a running target.
Both communicate with a host GDB or LLDB over the controlling terminal.
System extensions to the ptrace request set manage software
breakpoints and interrupt a traced process independently of job control.
The public struct reg represents the native integer register file
for AMD64, ARM64, PowerPC64 in both byte orders, and RV64. The application
tracing service runs on the RV64 native disk and the static application
debugger profiles for the other architectures. It
exposes resident process memory and lets the kernel validate register
writes, including the writable portion of the saved status register.
On platforms where the native disk image is unavailable, build with
--application-debug=y. The profile boots a read-only ext4 volume
from RAM with the native process supervisor, VFS, pager, and an
unprivileged diagnostic shell on the serial console. Debug sessions use
the ordinary application process and ptrace interfaces. See Boot, platform handoff, and service recovery.
-
struct ptrace_lwpinfo¶
Thread ID is relative to the selected process.
See also
Static and programmable tracing¶
Static kernel and server tracepoints use timestamps, per-CPU bounded buffers, and identifiable IPC and scheduling events. Preserve ordering and report loss. Correlate processes, kernel threads, and userspace server tasks with their IPC and scheduling events. Keep disabled probes inexpensive and include hardware counters and profiling as supported.
With system.trace enabled, the root supervisor receives a trace-stream
capability. trace_read requires read authority for that stream and write
authority for the destination frame. A call snapshots up to 64 records from
the calling thread’s last execution CPU or an explicit logical CPU index.
The kernel creates one 256-record ring per possible CPU when tracing is
enabled. A selector of zero follows the caller and a positive selector
encodes the CPU index plus one. Keep the selected CPU fixed across reads
that share a cursor. bpfctl and the native libbpf attachment path use
sched_getcpu() to select the caller’s CPU when no CPU is specified.
Each ring has a single producer that runs outside interrupt context.
The writer invalidates a slot before
replacing its fields and publishes a sequence stamp after the write.
Readers check the stamp before and after copying the fields. A concurrent
overwrite can shorten a batch to its stable prefix. The next read reports
any records lost since the cursor. A cursor ahead of the producer is
rejected before writing the frame.
-
struct native_trace_batch_t¶
One hart’s stable records starting at or after the requested cursor. The C declarations define event payloads, including scheduler migration masks.
Latency records carry elapsed clock ticks in value. IPC latency
measures successful synchronous calls. Wake latency measures the time
from making a blocked thread ready to dispatching it. Fault latency
measures the time to a successful reply from the userspace pager.
User timer exits record the interrupted program counter and task handle.
The root supervisor uses subject zero.
sched_migration records an automatic ready-queue transfer and places
the thread ID in subject. In value, bits 0–15 give the destination
CPU, bits 16–31 give the source CPU, bits 32–39 identify crossed topology
boundaries, and bits 40–47 identify the domains known at both endpoints.
Bit 48 marks an idle-destination transfer. Mask bits 0–5 represent core,
last-level cache, die, package, NUMA node, and performance domain. A
transfer can cross several boundaries. Count an undiscovered domain
separately from a shared or crossed domain.
sched_doorbell records a successful scheduler request to wake a
remote CPU. The destination CPU is in subject, and the sending CPU is
the ring owner. Hardware can coalesce requests before delivering an
interrupt. These events complement thread_migrate, which also covers
explicit affinity moves and boot fixtures.
On RV64 firmware with SBI PMU support, boot-hart samples can also carry absolute cycle and retired-instruction counts. ARM64 samples the boot CPU’s cycle counter when firmware exposes PMUv3 and also samples retired instructions when the PMU advertises that event and an event counter. AMD64 samples architectural fixed counters when CPUID enumerates them, or AMD extended core counters when exposed. PowerPC64 uses PMC5 and PMC6 for completed instructions and run cycles on recognized POWER7 through POWER11 processors. The PMU path keeps counter overflow interrupts disabled. Samples describe boot CPU activity across privilege transitions. They use the counters’ native units and wrap at their hardware width. User mode reads them through the authorized trace stream. A CPU or VM that exposes no PMU still produces sampled user PCs.
See also
RISC-V SBI PMU specification, Arm PMUv3 profiling guide, Intel Software Developer’s Manual, Volume 3B, AMD64 Architecture Programmer’s Manual, Volume 2, and POWER9 PMU User’s Guide.
Bring up live userspace debugging before programmable tracing. Use the existing static tracepoints for event ordering and use the debugger to inspect the verifier, runtime, and IPC clients as they come up.
Use eBPF as System’s programmable tracing framework. The kernel supplies
event collection and authorized export. Userspace owns program loading,
verification, execution, and instrumentation policy.
contrib/linux supplies the pinned BPF UAPI and a filtered set of
upstream BPF sources, documentation, and tests for reference. The service
executes probes with the userspace uBPF port.
On the RV64 native disk, bpfctl asks the supervisor for trace
batches through the native process endpoint. The supervisor authenticates
the caller by its process badge, checks the effective UID, and uses its
trace capability to write into the calling process’s transfer page.
The tool copies up to 16 batches. It releases root credentials, then
loads and executes the program in the same process. The interpreter works
from the copied records even as the live rings wrap. The kernel and the
supervisor can continue while the interpreter runs.
The loader accepts one executable section of a little-endian eBPF ELF
object without program relocations. The record layout and helper IDs are
defined in common/include/native_trace.h. The checked uBPF interpreter
grants read-only access to one record per invocation. Each invocation has
a 4,096-instruction budget. The loader limits the object to 64 KiB and its
program to 1,024 instructions. Map helpers operate on one 64-entry array
and one 64-entry hash map scoped to the invocation of bpfctl.
Array keys outside the map and insertions into a full hash map return
UINT64_MAX. Missing values read as zero.
The host PREVAIL tool checks the same record size, read-only context, and
scalar array and hash helper signatures through --system-trace.
The native loader and checked interpreter enforce their own limits at run
time. PREVAIL runs in the build-host environment.
The host bpf-btf command uses libbpf to read the object’s BTF and
render the probe’s C declarations.
Native BPF service¶
With --native-tracing=y, AMD64, ARM64 and both PowerPC64 byte orders
build the same userspace bpf server into the resident boot bundle.
On these profiles the supervisor exercises the tracepoint and map path
during the resident-service boot check. It loads native-endian BPF
instructions, reads a trace record through the probe, and checks that
releasing the owner detaches the link. The context record and instruction
immediates use native byte order. The service derives its poll interval
from the platform timer frequency.
On the RV64 native disk with the same option, the supervisor starts the
resident bpf server on the first authorized request. The process
endpoint authenticates the caller by its badge and checks its effective
UID. The server receives trace-read authority, a private snapshot frame,
and a control page shared with the supervisor. Applications submit requests
through system_bpf(). The supervisor forwards the authenticated PID
and copies only that application’s request and reply.
-
int system_bpf(unsigned command, struct system_bpf_request *request)¶
Control the BPF service. Returns a positive handle, zero, or -1 with errno.
-
struct system_bpf_request¶
Shared page input and output for a single native BPF operation.
Public Members
-
uint32_t object¶
Existing map, program, or link handle.
-
uint32_t type¶
Map or program type, or trace event for link creation.
-
uint32_t count¶
Map capacity, length of the program, or bytes in a ring sample.
-
uint32_t flags¶
Update policy, or 1 if GET_NEXT_KEY has a previous key.
-
uint32_t cpu¶
Trace source hart for link creation.
-
uint64_t seen¶
Link statistics or ring-buffer drops reported by SYSTEM_BPF_RING_INFO.
-
uint32_t object¶
The server owns loaded programs, maps, and attachment links. A program
retains its bound maps. Each link retains the program and detaches when
its last descriptor closes. Native libbpf creates VFS descriptors with
FD_CLOEXEC set. They can be duplicated, inherited by fork(), or
passed over a local socket with SCM_RIGHTS. Creation requires an
administrator. Existing descriptors authorize access to their object
after inheritance or transfer. VFS holds one reference per open file
description and can only ask the BPF service to drop that reference.
The supervisor resolves descriptors to object IDs before forwarding a
request. The private handle interface remains available for diagnostics
with system_bpf() and SYSTEM_BPF_CLOSE. The supervisor releases
those process-owned handles on exit, exec, or loss of administrator access.
-
int system_bpf_fd(unsigned command, struct system_bpf_request *request)¶
Control BPF objects through native file descriptors. New descriptors close on exec.
An attachment selects a System event or all events on one CPU. It begins at that ring’s current tail. The server polls in bounded batches, accounts for overwritten events, and runs checked uBPF on each selected record. It disables a link that exceeds its execution budget or fails a runtime check. Link status reports completed invocations, lost records, and failures. The kernel can keep producing events while the service runs probes. If the server itself stops replying, the supervisor times out the request and reclaims the service memory. The next authorized creation can start a fresh instance. The supervisor preserves the last issued object ID so descriptors from the failed instance cannot refer to newly created objects. VFS reports a final release timeout through its health check and completes the local descriptor close so process teardown can continue. Clients reload lost programs and maps and establish new links.
The service implements Linux’s numeric map and program-load commands
for an initial subset. Programs can bind owned maps with
BPF_PSEUDO_MAP_FD and call the standard lookup, update, and delete
helpers. Array and hash maps use 32-bit keys, 64-bit values, and up to
64 entries. The server limits each object class to eight live objects
and each program to 480 instructions. An invocation can execute up to
4,096 instructions. uBPF checks helper pointer arguments and bounds
lookup results to a single value. The native libbpf transport supports
the matching low-level calls with native descriptors. Attachment and
link status use system_bpf_fd().
On the RV64 native disk, libbpf uses libelf to open native-endian BPF
ELF objects and its upstream BTF parser to interpret .maps. The
object API creates array and hash maps, resolves R_BPF_64_64 map
references, and loads programs. Programs in
tracepoint/system/<event> attach by section name. A failed object
load closes the descriptors it created. The native profile limits
objects to 64 KiB and supports up to eight programs and eight maps per
object. The guest’s bpf-btf renders ELF and raw BTF as C declarations.
The tracepoint output path accepts Linux ring-buffer maps and the
bpf_ringbuf_output helper. An output map has a power-of-two byte
capacity between 4 KiB and 32 KiB, with records up to 512 bytes.
The interpreter checks the indicated readable memory and validates
initialized stack bytes before passing a record to the service. A full
ring returns EAGAIN and increments a drop counter. Descriptor holders
can read that counter and consume records in order. Native libbpf
retains a descriptor for each watched ring, reads records through IPC,
and calls the usual sample callback. The request returns the sample byte
count and uses its instruction array as the transfer buffer. The reader uses monotonic timeout polling
and delivers up to 64 samples per default call. The Linux wakeup flags
are accepted by the helper. External polling uses the native reader’s
timeout instead of an epoll descriptor.
The native root publishes the trace context’s target BTF at
/usr/share/bpf/system.btf. It is generated from the same public
header used by the kernel and the probe runtime. Libbpf resolves
.BTF.ext CO-RE records against this schema when opening an object,
before it creates any maps, programs, or links. A caller can select a
raw target schema with bpf_object_open_opts.btf_custom_path. Both
the object and the target schema are limited to 64 KiB. An incompatible
reference that would poison an instruction under Linux fails at object
open because the native interpreter checks every instruction. Split
BTF, global data, and BPF subprogram relocations remain unsupported.
bpfctl -a attaches a probe for one second. With -m it also
reports nonzero array and hash entries using Linux’s next-key operation.
Host PREVAIL’s --system-bpf mode
checks the tracepoint record and standard map helper contracts. The
RV64 C++ runtime supports locale facets, streams, and regular expressions.
The optional prevail package provides the native RV64 verifier. Its
--system-bpf mode verifies tracepoint objects against the native context
and map helper contracts. The same interface is available on the build
host. Native bpftrace requires native LLVM and additional libbpf
interfaces. Linux bpf() and
perf_event_open() belong to the Linux personality. A hook whose
result controls an operation belongs in the userspace server that owns
the operation. Linux seccomp filter semantics use a separate classic
BPF interface.