Debugging & Profiling
Maxon has an interactive debugger on every native target — maxon debug <exe>: breakpoints, stepping,
backtraces with inlined frames, and locals read out of the stopped thread. It launches the program
rather than attaching to one already running, and it drives it from outside through the host’s own debug
interface, so the program itself carries nothing of the debugger. Everything else on this page works on
every target: debug information beside every binary, panic backtraces, a leak check, a trace monitor, a
sampling profiler and code coverage.
The examples below use output from real runs; addresses, counts and timings vary from build to build.
The .mxdbg debug-info sidecar
Section titled “The .mxdbg debug-info sidecar”Every compile maxon build performs writes a sidecar named after the full output file, beside it, unless
you pass --no-debug-info or the described build sets debugInfo: false:
[CMP] INFO: compiling app.exe: no record of a previous build[CMP] INFO: Wrote 35598 bytes of debug info to app.exe.mxdbg[CMP] INFO: Wrote 103992 bytes of code to app.exe (compiled in 0.3 s)Compiled -> app.exeOn Linux and macOS the executable is app and the sidecar app.mxdbg. No sidecar is written for
wasm32-wasi. The executable is byte-identical with or without the sidecar, so the code you debug is
the code you ship.
The sidecar maps machine code back to the source. It records the target, a build id (a hash of
the executable’s code section) and the directory the build ran in, then the source files, functions with
their prologue offset, frame size, local variables and origin, types, the line table and inlining
records, and the image base, the .data words a debugger reads out of the running program and the record
geometry it reads them by. maxon debug prints it; maxon profile and maxon coverage read it, and a
--coverage build requires it.
The sidecar format is versioned (version 11), and a reader refuses a sidecar of any other version: after upgrading the compiler, rebuild before debugging, profiling or reporting coverage.
Panics and backtraces
Section titled “Panics and backtraces”A runtime panic (a failed range check, an explicit panic, an out-of-bounds access) prints the message
with its source position, then the call chain, to stderr, and the program exits with code 1:
panic at app.maxon:21: Range check failed: value outside typealias 'Byte'Stack trace: in narrow in main in mrt_startFrames are listed innermost first, by function name only, down to the program’s start (mrt_start).
At most 100 frames are printed; a deeper chain
ends with an ...additional frames elided... line. A processor fault has no source position, for example
panic: nil pointer or invalid memory access or panic: stack overflow, followed by the same stack trace.
On x64-windows, a fault on a green thread whose stack has no room left for the operating system’s exception
dispatch ends with fatal error: exception dispatched below green thread stack bottom and exit code 70.
A wasm32-wasi program panics the same way: the same message, the same trace with the same function
names, and exit code 1. A memory fault or a stack overflow there is a trap in the WebAssembly runtime,
which prints its own report and chooses the exit status.
The leak check
Section titled “The leak check”A program that allocates checks, after main returns, that every heap allocation was released. If one
was not, the program prints nothing and exits with code 101 instead of the code main returned. Maxon
releases memory itself, so there is no call you forgot to make: exit 101 points at the memory management
the compiler emitted. maxon test reports such a test as LEAKED, and
maxon monitor --filter=mm shows every allocation and free.
maxon debug
Section titled “maxon debug”Debugs a program interactively, and reads the .mxdbg sidecar back. The two sidecar forms are read-only
and accept either the executable or the sidecar itself; the debugger forms launch the executable.
maxon debug <exe> [--trace] [--stop-timeout=<seconds>] [--target-env=NAME=VALUE]... [-- <program args>...]maxon debug --batch --commands=<cmd;cmd;...|@file> <exe> [same options]maxon debug --complete=<partial line> <exe>maxon debug --classify=[arm64:]<hex>[,<hex>...]maxon debug --dump-info <exe|.mxdbg> [header|files|functions|types|lines|statements|inline|globals|layout]maxon debug --symbolize <exe|.mxdbg> <codeOffset...>| Option | Description |
|---|---|
--batch |
Run --commands= instead of prompting, and write one JSON object per line on stdout |
--commands= |
The commands --batch runs, separated by ;, or @<path> to read them from a file |
--complete= |
Print the completions for a partially typed debugger line, one per line, and run nothing |
--classify= |
Classify raw instruction bytes the way arming a breakpoint does, and run nothing. The bytes are x64’s; a leading arm64: reads the whole list as arm64 |
--trace |
Create the DebugStream ring the trace command reads, and name it to the debugged program |
--stop-timeout= |
Seconds to wait for a stop, and the budget for one driver-walked step (default 10). A fraction is honoured to the millisecond; a value outside 0.001 to 922337203685 is refused, naming the option. |
--target-env= |
Set a variable in the DEBUGGED program’s environment; repeatable |
--dump-info |
Print the sidecar, or only the sections named after the path |
--symbolize |
Resolve offsets into the executable’s code section to file:line:col |
maxon debug with no arguments prints the usage above and exits 1.
The session. The driver launches the program under the host’s own debug interface and takes the stop
the loader gives it before any of the program’s code runs, then arms whatever was asked for. A
breakpoint is the driver saving the original bytes and writing the host’s own trap instruction over them
through the debug interface — an int3 on the x64 hosts and a brk #0 on the arm64 ones; resuming off one
restores the bytes, single-steps the instruction with every other thread held, and plants the trap again.
The host keeps the pair together: quitting the session ends the program with it, and detach is how you
leave a program running.
A program the debugger cannot drive is refused by name, with exit 1: every program on a host this build
has no debug backend for (naming the host), a wasm module, a binary built for a target other than this host’s
(refused before launch, naming both targets), an arm64-macos program on a host with no debugserver (naming
xcode-select --install), and a binary whose sidecar describes a different build.
On arm64-macos the driver checks that the host’s debugserver takes --unmask-signals, which is what lets a
hardware fault reach the program’s own handler; where an older one is found the driver says so on stderr, and
xcode-select --install updates it.
The driver reads the stub’s packets until a request’s own reply arrives. A stop the program reaches in the
meantime is held and reported by the next wait. A report that the program ended fails the waiting request
at once and is reported by the next wait. A detach the stub has not answered ends when the program ends:
the stub is ended and detach reports the program’s ending. A reply to detach, to planting or lifting a
breakpoint, or to a memory or register write that is anything but OK is printed on stderr as
maxon debug: the debug stub answered something that is not an acknowledgement: '<reply>' to '<request>',
and the operation is refused.
Commands, with their aliases: break (b) · clear · run (r) · continue (c) · step (s) ·
next (n) · finish · until (u) · backtrace (bt, where) · print (p) · locals · pause ·
threads · gt-backtrace · gt · gt-park · gt-resume · trace · detach · help (?, commands) ·
quit (q, exit).
detach restores every byte the debugger wrote, lifts every held green thread, puts asynchronous
preemption back and lets the program run on under its own steam; the session then waits for the program’s
own ending and reports it; an ending whose exit status went to another process is reported as the program ended, and its exit status went to another process, so it is not available. On arm64-macos the re-signed copy the program was launched from is removed at
the detach, and the program keeps running from the file it already has open. While a trap byte cannot be
written back, detach is refused unwritable with every breakpoint the debugger could write back
cleared, and the program stays attached. A program that ended while the session held it has nothing left
to write back to: detach and quit report its ending. After a detach, every command except help and quit is
refused: the session has detached, the program runs on by itself out of the debugger’s reach, and
only quit remains. An ending the program reached in the meantime is reported first.
quit leaves a detached program running.
A kernel that refuses to let the program go, or a debug stub that answers neither the detach’s probe
nor the interrupt that follows it, refuses the detach detach-refused. After it, every
command except help and quit is refused: the detach failed, the program’s state is unknown (it may
be running), and only quit remains. quit then ends the program, as it does in a session still
attached to it.
On arm64-macos a detach first probes the held program: the stub single-steps the stopped thread
once, every other thread held, so a kill already pending on the program lands while the stub still holds
it. A program that ends on the probe is reaped by the stub and reported ended (a SIGKILL as exit code
137), and the detach ends there. A step that lands, or a thread that ends under it, leaves the program held, and the
detach request follows. A probe the stub leaves unanswered is drained with an interrupt before anything
else is sent. A pause stop, and a stop whose thread has since ended, is detached without a probe.
On arm64-macos a detach the stub has answered waits up to a second for the program to become the
session’s own child again, and only then ends the stub. A program the stub still holds after that is
refused the-stub-still-holds-the-program, and the stub keeps holding it. After it, every command
except help and quit is refused, and quit ends the program through the stub.
break <target> if <local> <op> <literal> arms a conditional breakpoint the driver judges at the stop, so a
hit that fails it resumes at once; a condition over a float, a String, a field path, a constant or a local
the breakpoint’s pc has no record for is refused condition-unsupported and leaves the breakpoint unarmed,
and a literal that fails to parse is condition-invalid. A literal is decimal or 0x hex, optionally led
by -, from i64.min to u64.max; one above i64.max is condition-invalid against a signed local.
A local of an integer alias whose lower bound is 0 or above prints and compares as its unsigned value,
so a Count above i64.max reads as the number it holds.
pause interrupts a program that stops on nothing and publishes a pause stop. threads lists the
program’s green threads, gt-backtrace <id> walks one, gt <id> selects the thread that print,
locals and backtrace answer about (gt alone clears it), and gt-park <id> / gt-resume <id> hold a
thread off every machine and let it go again. Wherever an id is taken, the selectors running, ready,
waiting and held name the lowest-numbered thread of that status instead, and <status>:<function>
narrows to the threads whose entry function has that name — a batch script cannot know an id in advance.
trace [N] prints the last N DebugStream events committed before the stop (20 by default), and needs
--trace on the session and --debugstream on the build.
Stepping is refused while a gt selection is on, a register-located local of a selected thread reads
unavailable: "register-of-parked-thread", and an id names a thread only for as long as that thread
lives: every word that names one re-lists the roster first, and an id whose thread has ended is
no-such-thread. The other refusals are:
thread-is-running— for a thread on a machine.not-pausable— for a program the host would not interrupt, or one that did not stop within the attempt budget.not-running— for a word that needs a stop while the program is running.fault-is-terminal— for a step from afaultstop.paused-in-no-program-code— for a step from apausestop that stands in no code of the program’s own.unwritable— for a byte the debugger could not write into the program’s code.detach-refused— for adetachthe kernel refused to carry out, or whose probe the debug stub never answered; the program’s state is unknown and onlyquitremains.the-stub-still-holds-the-program— for adetachonarm64-macoswhose stub had not handed the program back within a second; the program stays with the stub and onlyquitremains.inside-runtime-symbol— for abreakat code that is the runtime’s own: the runtime tier, and anything the compiler synthesized.
A stop carries a reason: entry before main, breakpoint, step, pause, trap and fault.
trap is a trap instruction the debugger did not plant — a stop like any other, with a register file and a
stack to walk, which continue resumes past. fault is a hardware fault the program would otherwise panic
on (an access violation, a stack overflow, an integer divide by zero or an integer overflow), stopped at the
faulting instruction with a fault field naming it in the words its panic line uses. On x64-linux,
arm64-linux and arm64-macos the debugger also stops on a misaligned access, named misaligned or invalid memory access, and on an illegal instruction, named illegal instruction; a fault arrives on those three
hosts as a signal number alone, so the field names integer divide by zero for both arithmetic faults and
nil pointer or invalid memory access for both memory faults. Any other fault code a host reports is named
hardware fault and that code. A fault inside library code is positioned at the program’s own call into
it. The faulting instruction would fault again, so a step from a fault stop is refused
fault-is-terminal, and continue hands the fault to the
runtime, which ends the program with the same panic line, backtrace and exit code it has undebugged,
reported as a crash. A stop also carries the machine (the OS thread id that took it), its thread
id when a green thread was running, and its function when its position lies in one.
Every stop stops the whole program. A debug event holds every thread of the program until the driver
answers it, so the roster, a parked thread’s stack and the memory a print reads are one consistent
picture, and continue or a step releases them together. A pause of a program whose threads are all
idle stands in no code of the program’s own: its backtrace lists the runtime frames the stopping thread
waits in, down to mrt_start, and threads and gt-backtrace answer as usual. On Windows the idle wait
sits in a system library that breaks the frame chain, so that backtrace is empty. A step, next
or finish from such a stop is refused paused-in-no-program-code.
Two costs are worth knowing. A held thread is refused each time a machine reaches it, and that machine
pauses and looks again, so a hold is a polite spin rather than a parked thread. And a pause asks the
host to interrupt the program and then waits for the stop that follows, so a program that produces none
within the attempt budget answers not-pausable.
The running state. A run, continue or step that reaches --stop-timeout= answers timeout and
LEAVES THE PROGRAM RUNNING. In that state break, clear, pause, threads, gt-park and gt-resume
are serviced while it runs and continue waits again; backtrace, print,
locals and the steps answer an error until something stops. The session’s exit code is still 1 once
anything has timed out, and the program is reaped when the session closes.
A stop that lands while the program runs is reported ahead of the next command’s answer: a stop that came before the command, or one the program was already in when the command was answered, precedes that answer in the transcript, so each event sits where it happened.
A break target is file.maxon:LINE, a bare LINE in the file that declares main, *0x<offset>, or a
function name resolved exact → Type.method → leaf name → word prefix. More than one match answers
ambiguous with the candidates; a name nothing answers to names the nearest function. Lines are numbered
from 1, so line 0, bare or in a file, is an error saying so.
- A file is named by the most specific spelling given: a full path names that one file; a relative
path with a directory names the file it reaches from the directory the program was built in, or else
every source file whose path ends in it; and a bare file name matches every source file of that name.
A spelling that matches more than one file answers
ambiguouswith the candidates. *0x<offset>arms the instruction at that offset into the code section, the offsets--dump-infoand--symbolizeprint. An offset past the code, or in no function, is refusedout-of-text; one that falls inside an instruction, past its first byte, is refusednot-an-instruction-start.- A line arms wherever control enters it: the
line-entryrows of the line table. A line the inliner copied into several places is armed at every copy. A line whose only code is an inlined call arms at the call: the stop is at the call line in the caller’s frame,nextruns over the inlined body andstepenters it. As in gdb, the inlined body joins that stop’s backtrace once it is entered. A line whose only code is a narrowing cast’s range check is a line with code. A line with none answersno-code. - The runtime’s own code — the entry stub, the scheduler and the rest of the compiler’s scaffolding
— is refused
inside-runtime-symbol. Which code is the runtime’s is recorded by the build, and code the compiler inlined is judged as the body it came from: an offset inside a service’s message handler, inlined into the behaviour function the compiler synthesizes, is armed and stops as the handler. Atestbody is the program’s own, and is namedtest '<prose>'in stops, backtraces and break answers, asmaxon testnames it.
step enters a callee, next stays in the frame it was issued from, finish runs to the return of its
frame and until runs forward past the current line. Each walks the program’s own code one instruction
at a time, and runs other code at full speed to a temporary breakpoint:
nextanduntilrun a call they reach, direct or through a value, to its return address.finishfrom a function’s own frame runs to that frame’s return address. A recursive call that reaches the address in a deeper frame runs on.stepinto a library function runs it to the return into the program’s code.- Library code the compiler inlined into the program’s frame runs to the one place control leaves it.
Under
stepit does so when the inlined code, and every function it calls directly, is library code, and a temporary breakpoint also stands on each call it makes through a value, so a closure of the program’s that the library calls is still stepped into. Inlined code with more than one way out is walked.
Each honours any breakpoint it passes — except the one it started on — and each is bounded by
--stop-timeout=. A finish from the outermost frame is refused.
$ maxon debug --batch --commands="break app.maxon:12;run;locals;next;backtrace;continue" app.exe{"event":"breakpoint","action":"set","function":"work","file":"app.maxon","line":12,"offset":"0x7a"}{"event":"stop","reason":"breakpoint","function":"work","file":"app.maxon","line":12,"col":9,"offset":"0x7a","machine":5312,"thread":1,"source":[…],"backtrace":[…]}{"event":"locals","function":"work","locals":[{"name":"total","type":"Amount","kind":"int","display":"42"}]}{"event":"stop","reason":"step","function":"work","file":"app.maxon","line":13,"col":3,"offset":"0x7e","machine":5312,"thread":1,"source":[…],"backtrace":[…]}{"event":"backtrace","frames":[{"frame":0,"function":"work","file":"app.maxon","line":13,"col":3,"offset":"0x7e"}]}{"event":"exit","code":0}A function value’s kind is Function and its display is the function it calls. A capturing closure
displays as the function the compiler lifted its body into (render$closure_0), with each captured value
as a child under the name it was captured by.
In --batch stdout is pure JSON, one object per line, and the debugged program’s own stdout and
stderr both go to this driver’s stderr. The events are breakpoint, stop, backtrace, locals,
value, threads, gt-backtrace, gt-select, gt-park, gt-resume, trace, exit, crash,
timeout and error. A list that cannot be produced is null beside a <name>Unavailable reason, and a
value that cannot be read carries unavailable with one of optimized-out, not-live-here,
read-failed or layout-not-described. A stop, breakpoint, locals or thread row carries
function when its position lies in a function, and a backtrace frame carries its col beside its
line. A breakpoint event carries offset when its answer names an offset, and offsets beside it
when the answer names several. A refusal, condition-* included, names the offsets refused for the
reason it reports, and a *0x<offset> target the offset asked; not-set, no-match, ambiguous and
no-code answers name none. reason comes with a refused answer. A trace event carries since,
the previous stop’s position in the ring, when there was a previous stop.
The driver exits 0 when the session completed — the program’s own exit code is DATA in the exit event —
and 1 on a timeout, a refused session or a crash. A session that lets the program finish and cannot
remove a breakpoint’s trap says which offsets stand, closes the program instead and exits 1. A command issued after the
program has ended is an error, and the verdict stands.
Without --batch the same commands are read from stdin, one per line, and answered as text for a
person; end of input quits. The debugged program’s streams pass through to this driver’s own.
After the program exits the driver forwards the rest of its output until both streams end. A process
the program started can hold them open, so the wait ends once no output has moved for 1 second, or 10
seconds after the exit, whichever comes first. Then stderr gets
maxon: the target's output is still held open after it exited, so the rest of it is not waited for, and
the session reports the exit as usual.
--classify= is the door onto the instruction classifier the step planner and the stack unwinder
read. It reads no program:
$ maxon debug --classify=488d0dce6f0000,c21000,ff5008,62len=7 class=2 cond=0 disp=3 target=0x7fd5len=3 class=6 cond=0 disp=0 target=0x0 rel=1len=3 class=7 cond=0 disp=2 target=0x0 operand=mem:base=0,index=none,scale=1,disp=+0x8unclassifiedThe classes are 1 plain, 2 pc-relative data, 3 direct call, 4 direct jump, 5 conditional jump, 6 return,
7 indirect call and 8 indirect jump. A breakpoint is armed at any instruction the classifier decodes,
whatever its class; bytes it cannot decode answer unclassified, and a break there is refused by that
name. Every address is computed against a fixed probe address, 0x1000:
targetis the absolute branch target for 3, 4 and 5 and the absolute referent for 2.dispis the byte position of the displacement of a memory operand, andcondthe condition code of a conditional jump.rel=on a return is the byte position of the immediate aret imm16releases, and0for aretthat releases nothing.operand=on an indirect call names what it calls through:reg:<n>a register;word:0x<address>a pc-relative word at that absolute address;mem:base=<n>,index=<n>,scale=<s>,disp=<±0x…>a memory word, withnonefor an absent base or index; andoverridden:form=<n>an operand behind a segment or address-size prefix, whose word the classifier leaves unresolved (form1 register, 2 memory, 3 pc-relative).
A leading arm64: reads the whole list as arm64 instructions, against the same probe address:
$ maxon debug --classify=arm64:00008052,00000094,400000b4,00021fd6,fd7bbfa9,ea000054len=4 class=1 cond=none target=0x0 reg=none frame=nonelen=4 class=3 cond=none target=0x1000 reg=none frame=nonelen=4 class=5 cond=none target=0x1008 reg=0 frame=nonelen=4 class=8 cond=none target=0x0 reg=16 frame=nonelen=4 class=1 cond=none target=0x0 reg=none frame=opens-recordlen=4 class=5 cond=10 target=0x101c reg=none frame=noneEvery instruction is four bytes, and the classes are the same numbers; arm64 control flow reaches 1, 3, 4, 5, 6, 7 and 8.
condis the condition code of ab.<cond>, andnoneon every other instruction.regis the register control leaves through on 6, 7 and 8, and the register a compare-and-branch tests on 5; an instruction that names neither answersnone. Abr x30is a return, 6, asretis: it is how a function whose frame can resume after a green-thread switch returns.frameis what the instruction does to the frame, which the stack unwinder reads:opens-recordfor anstpthat pre-indexessp,reservesfor asub sp, sp, #imm,stores-recordfor anstpat an offset fromsp,sets-pointerfor anadd x29, sp, #imm, andnonefor anything else.
Sections of --dump-info (with none named, all are printed):
| Section | Contents |
|---|---|
header |
The file, target, build id and root, the directory the build ran in, from which the recorded relative source paths are read |
files |
The source files, including the standard-library and runtime files the program uses |
functions |
Each function’s code range, prologue=+0x… (how far past its entry its prologue starts: the length of the green-thread stack guard ahead of it, +0x0 when none), frame size, parameter, line and local counts and origin, then as <name> when the debugger shows it under another name (a test body is shown as test '<prose>'); and, per local, the code range [start, end) over which its location holds the local’s current value: the range opens after the instruction that makes the value current (the store for a frame slot, the defining op for a register) and ends at each exit from the local’s scope, and a value kept in a frame slot also covers the blocks its definition dominates until another assignment of that name; then its location, in [n] when it belongs to inline site n, and its type. A location is a frame slot, a register, <optimized out>, = v for a value folded to a constant or = {…} for a whole record folded to one; a * after it means the location holds a pointer to the value rather than the value. A name with several live runs has a row per run, and one name’s rows in different places never overlap. |
types |
Each type’s kind, size, alignment and fields, with (signed) on a type whose values are signed and an element row on an array’s |
lines |
The line table: code offset, source position and flags — statement, coverage, and line-entry on a row where control enters its source line: falling in from a different line, at the function’s entry, or through a branch from another line |
statements |
The same table, without the code offsets |
inline |
Inlined call sites, each with the site it nests under, the position of its call and its origin, then the code ranges they occupy |
globals |
The .data words a debugger reads out of the running program: each one’s name, its offset from the image base and the width it is read at: its slot’s, or a machine word for a run wider than one, which is published as its first word |
layout |
The record geometry it reads them by: each figure’s name and value |
An origin says where a function or an inlined body came from: authored (the program’s own source),
test (a test body), library (the standard library or a scriptlib package), runtime (the runtime tier), generated
(source the compiler wrote for this build) or synthesized (code with no source, such as the entry
stub). Code inside an inlined body has that body’s origin. The debugger treats authored and test
code as the program’s own, and refuses a breakpoint at runtime or synthesized code by that origin.
The profiler counts every frame but a runtime or synthesized one toward the program.
$ maxon debug --dump-info app.exe headerDebug info: app.exe target: x64-windows build-id: 0xb1c1a21a3d5126c2 root: C:\work\app
$ maxon debug --dump-info app.exe functions functions (109): mrt_start [0x0000, 0x002e) prologue=+0x0 frame=0x20 params=0 lines=0 locals=0 origin=synthesized main [0x0040, 0x021c) prologue=+0x0 frame=0x48 params=0 lines=21 locals=9 origin=authored limit [0x0040, 0x021c) = 64 : Amount points [0x0065, 0x021c) [rbp-0x50]* : Array_Amount total [0x0085, 0x0089) reg2 in [0] : Amount
$ maxon debug --dump-info app.exe inline inline sites (385): [0] worker called at app.maxon:17:15 origin=authored [1] print called at app.maxon:20:2 origin=library
$ maxon debug --dump-info app.exe lines line table (2484): 0x0051 app.maxon:14:15 [statement] 0x0078 app.maxon:6:11 [statement, line-entry]A word that is not a section is refused before the file is read:
maxon debug --dump-info: 'bogus' is not a section (header|files|functions|types|lines|statements|inline|globals|layout).--symbolize takes offsets in decimal or 0x-prefixed hex and prints one line each. An offset
before the function’s first statement prints <no line>. An unreadable offset is reported and the
command exits 1 after printing the others.
$ maxon debug --symbolize app.exe 0x00e0 0x0151 zz0x00e0 <no line> (in main)0x0151 app.maxon:25:15 (in main)Not a code offset: 'zz' (use decimal or 0x-prefixed hex).The build id. Given an executable, or the .mxdbg path beside one, maxon debug checks that the
sidecar was written by the same build as that executable, and refuses a stale one with exit 1:
maxon debug: the .mxdbg sidecar describes a different build of this binary — rebuild itA missing sidecar is refused with exit 1, naming the path it looked for and --no-debug-info as the
likely cause. maxon debug reads PE, ELF and Mach-O executables whatever the host, so it works on a
cross-compiled binary.
maxon monitor
Section titled “maxon monitor”Launches an executable built with --debugstream and prints the trace events it writes into a
shared-memory ring. Each event line is prefixed with the time since start as [+SSSS.mmm]. The monitor
creates the ring and passes its name to the program in the MAXON_DEBUGSTREAM environment variable.
Only the program itself reports events; the processes it starts report none. The program’s own stdout
and stderr pass through unchanged.
maxon monitor [--filter=mm|sched|log] <exe> [args...]Everything after the executable is the program’s command line and reaches it untouched.
| Option | Description |
|---|---|
--filter=mm |
Memory-manager events only: mm_alloc, mm_free, mm_incref, mm_decref and related |
--filter=sched |
Green-thread events only: sched_spawn #N, sched_await #N (the thread awaited), sched_yield #N and sched_resume #N (around sleep and Scheduler.yield()), io_yield #N and io_resume #N (around a blocking I/O operation). N is the thread’s number, the same one --async-trace prints. |
--filter=log |
Only the events the program emitted through the __DebugStream builtin |
With no --filter, every family is printed. An unrecognized value is refused with the usage line.
$ maxon build app.maxon --debugstream$ maxon monitor --filter=mm app.exe[+0000.015] mm_alloc ArrayRecord #1 size=48[+0000.015] mm_alloc Point #2 size=16[+0000.015] mm_alloc ElementBuffer #3 size=32...points=1000 worker=42[debugstream] 3063 events, 0 dropped, peak buffer: 0.0 MB / 2.0 MB (2%)Events go to stdout; the closing [debugstream] summary goes to stderr.
After the program exits, its remaining output is forwarded under the bound and with the stderr notice
described under maxon debug.
A binary built without --debugstream is refused before it starts:
maxon monitor: could not read the interned name tables out of the target (app.exe has no .symtab section)Exit codes: the program’s own exit code (a panicking program’s 1 included), except 1 for a
command line monitor cannot act on (no executable, no such file, an unknown filter, a binary built
without --debugstream) and 3 for a trace this compiler cannot decode, which asks you to rebuild the
program.
Emitting your own events. A --debugstream build enables the __DebugStream builtin, which puts
events from your code into the same ring. Without --debugstream, every call compiles to nothing; with no
monitor attached, __DebugStream.enabled() is false.
| Call | Event | Notes |
|---|---|---|
__DebugStream.enabled() |
— | true when a monitor is attached, so a caller can skip building a message nobody reads |
__DebugStream.nameId("phase") |
— | Interns a name at compile time and returns its id. The argument must be a string literal. |
__DebugStream.phaseBegin(nameId, unitId) |
log_phase_begin |
Opens a nested span |
__DebugStream.phaseEnd(nameId, unitId) |
log_phase_end |
Closes it |
__DebugStream.event(nameId, cat, lvl, unitId, arg0, arg1) |
log_event |
A name and two numbers; allocates nothing, so it is safe on a hot path |
__DebugStream.text(cat, lvl, unitId, message) |
log_text |
A UTF-8 message, truncated at 64 KiB |
Each event line names the green thread and processor that emitted it (gt=0x0 P0).
maxon profile
Section titled “maxon profile”Launches a program and samples where its CPU time goes. The program needs no instrumentation: only its
.mxdbg sidecar is read, so you measure the code you ship. The program’s own output goes to stderr, so
stdout is only the report. After a run that completes, the program’s remaining output is forwarded under
the bound and with the stderr notice described under maxon debug.
It runs on every native host — x64-windows, arm64-macos, arm64-linux and x64-linux — and profiles
a program built for that host. Each tick stops a thread, reads its registers, copies its stack and lets it
go: through thread handles on Windows, Mach task and thread ports on macOS, and ptrace on Linux.
- arm64-macos hands out a program’s task port only when its image is signed with the
com.apple.security.get-task-allowentitlement and the user has Developer Tools Access (DevToolsSecurity -status). No build carries the entitlement, somaxon profile,maxon debug,maxon dap-serverand the MCPdebug_*tools launch a re-signed copy of the program, made in process without recompiling. Only the copy’s code signature differs from the original. The copy sits beside the original, in the same directory, named<program>.<block>.attached, so a program that looks beside its own executable finds what the original has there. The program sees the copy’s path as its executable (Process.executablePath()) and asargv[0]; the debug-info sidecar, the build identity and the name in a report are the original’s. The tool deletes the copy when the run ends or the session detaches, and removes the copies of runs that ended without doing so, found by the owner recorded in the name, at the start of its next run in that directory. A directory the tool cannot write the copy into is refused, naming the directory. A program that is not an arm64 Mach-O this compiler wrote, or whose signature is malformed, is refused with the reason. - arm64-linux and x64-linux attach with
ptrace, whichkernel.yama.ptrace_scope0 or 1 allows for the profiler’s own child. A thread is stopped only for its tick and detached before the next. A thread that cannot be detached within 10 seconds has its whole process killed rather than left stopped, and stderr says so in one line per process:sampler: thread <tid> of process <pid> could not be detached within 10000 ms, so the process was killed rather than left stopped. A signal that arrives while the profiler holds a thread, such as the runtime’s preemption signal, is delivered to the thread when the profiler detaches it. - A thread in uninterruptible sleep (
Din/proc/<pid>/task/<tid>/stat) is waited on when it is the program’s main thread at the start, for the same 10 seconds, and then treated as traceable. Any other thread found in that state on a tick is counted as an unreadable stack for that tick.
On Windows a thread’s time is read from its cycle counter, calibrated against the clock before the run; on macOS and Linux it is read as CPU nanoseconds.
maxon profile run <exe> [--json|--folded] [--rate=<hz>] [--min-percent=<share>] [--timeout=<seconds>] [--target-env=<NAME>=<VALUE>]... [args...]| Option | Description |
|---|---|
--json |
Emit the full report as JSON instead of a summary |
--folded |
Emit collapsed stacks (root;child;leaf <count>), the format flamegraph.pl, inferno and speedscope read. --json and --folded together are refused. |
--rate=N |
Samples per CPU-second a thread consumes (default 1000, from 1 to 10000). A thread is charged by the CPU time it used, so an idle thread costs almost nothing. The report shows the rate achieved beside the one requested. |
--min-percent=N |
Hide rows below this share of the run from the printed tables (default 1). The number hidden is always reported. |
--timeout=S |
Stop the program after S seconds (default 600) and report what was sampled, marked PARTIAL |
--target-env=N=V |
Set a variable in the profiled program’s environment (repeatable). --target-env=MAXON_MAX_PROCS=1 pins the scheduler’s processor count, which makes a green-thread profile reproducible. |
$ maxon profile run busy.exeprofile: busy.exetarget exit code: 0samples: 2204 from 2060 captures at 1000 Hz over 2.3066124s (requested 1000 Hz)unsymbolized: 2 samples (0.1%)runtime: 0 samples (0.0%) in the runtime's own machinery, which no row below listsstacks: 0 truncated, 1 unreadable
=== hot functions (self time) === 99.5% 2193 mix (4 functions below 1% not shown)
=== call tree === 99.9% 2202 mrt_start 99.9% 2202 main 99.9% 2202 spin 99.5% 2193 mix (1 nodes below 1% not shown)
=== stacks === one row per stack that ran — an OS thread's or a green thread's — named by its outermost frame 99.9% 2202 mrt_start (1 stacks below 1% not shown)$ maxon profile run busy.exe --folded[ntdll.dll] 1mrt_start;main;spin 10mrt_start;main;spin;mix 2194The runtime: line counts the samples whose stack, as far as its walk read it, ran only the runtime’s
own code, such as the loop a scheduler worker runs between green threads or a context switch. Those
samples are counted on that line alone. Library code counts toward the program, and code the compiler
inlined is named as the body it came from, so a service’s message handler, inlined into the message
loop the compiler synthesizes, has rows of its own. On macOS a thread stopped just as a signal reaches it,
such as the runtime’s preemption signal, is sampled as the code the signal interrupted; a sample anywhere
else in the system’s signal trampoline is the runtime delivering the signal and counts on the runtime:
line. On x64-windows, whose system DLLs keep no frame-pointer chain, a sample inside a system DLL is
walked from the last Maxon frame the runtime saved around the call, so its row carries its Maxon callers
(mrt_start;main;wait;[ntdll.dll]) and a wait inside the runtime counts on the runtime: line; a bare
[ntdll.dll] row is a sample in a DLL with no saved frame. A thread that ends while it is being sampled is
dropped without a sample for that tick.
The stacks section has one row per stack. Its name is the outermost frame the profile could name; when samples of one stack name different frames, the row takes a named frame over a bracketed one, then the first in byte order.
--json prints one object with exe, targetExitCode, runCompleted, achievedRateHz,
requestedRateHz, samples, captures, samplesUnsymbolized, samplesInRuntime and related counts, and
the arrays functions (name, selfSamples, totalSamples), tree and stacks.
Exit codes: 0 when the measurement completed. 1 for a refusal (no such executable, no sidecar, a
sidecar from a different build, an arm64-macos image it cannot re-sign or a directory it cannot write
the signed copy into, a host that refuses to let the profiler attach, a program whose loaded images cannot
be listed or, on arm64-macos, in whose images the system’s signal trampoline cannot be located, a program
that ended before sampling began)
and for a run stopped by --timeout, whose partial report is still printed. The program’s own status is
the target exit code line.
maxon coverage
Section titled “maxon coverage”Reads back what a --coverage build counted, as line and branch coverage. The instrumented program
writes its counters to <exe>.mxcov as it exits.
maxon coverage <run|report> <exe> [--json] [--data=<file>] [--timeout=<seconds>] [args...]rundeletes the previous counter file, launches the program, then reports on the counters it wrote. The program’s output goes to stderr, so stdout is only the report. Arguments after the executable are the program’s.reportreports from counters an earlier run wrote, and launches nothing.
| Option | Description |
|---|---|
--json |
Emit the report as JSON instead of an annotated source listing |
--data=F |
Read counters from F instead of <exe>.mxcov. For report only; run refuses it. |
--timeout=S |
Kill the program after S seconds (default 600) and report nothing. A fraction is honoured to the millisecond; a value outside 0.001 to 922337203685 is refused, naming the option. For run only. |
$ maxon build cov.maxon --coverage$ maxon coverage run cov.execoverage: cov.exetarget exit code: 0lines: 5/6 covered branches: 1/2 arms taken eliminated: 0 lineslegend: a count = executed, ##### = never executed, ----- = no code emitted (optimized away), blank = no coverage point
=== cov.maxon === | 3| function classify(n Count) returns String 3 | 4| if n > 5 'big' ##### | 5| return "big" | 6| end 'big' | 7| 3 | 8| return "small"...=== branches === cov.maxon:4:2 then@4=0 else(implicit)@4=3maxon coverage report cov.exe prints the same report without the target exit code line. With
--json the report is one object with exe, runCompleted, linesCovered, linesInstrumented,
linesEliminated, armsTaken, armsInstrumented, and files (each line’s state and count) and
branches arrays.
Exit codes: 0 when a report is produced, 1 for a refusal, such as a binary built without
--coverage:
coverage: app.exe was not built with coverage instrumentation — it has no coverage points to report onThe program’s own status is the target exit code line.
Tracing green threads
Section titled “Tracing green threads”A build with --async-trace writes one line to stderr each time a green thread is spawned, sleeps,
waits on I/O, resumes, or is awaited. Without the flag, no trace code is emitted.
$ maxon build app.maxon --async-trace$ ./app.exespawn #1sleep_yield #1sleep_resume #1await #1 [yield]points=1000 worker=42| Line | Meaning |
|---|---|
spawn #N |
Green thread N was started |
sleep_yield #N, sleep_resume #N |
It gave up its processor to sleep, and resumed |
io_yield #N [kind], io_resume #N [kind] |
It waited on I/O (for example [file_exists], [net_connect], [net_recv]), and resumed |
await #N [yield] |
It was awaited and the caller had to wait |
await #N [immediate] |
It was awaited after it had already finished |
try_await #N |
The same, for a try await |
Investigating a running program
Section titled “Investigating a running program”- A panic: read the backtrace, then map positions with
maxon debug --dump-info <exe> linesormaxon debug --symbolize. - Green threads that stall or run out of order: build with
--async-trace. - Memory: build with
--debugstreamand runmaxon monitor --filter=mm. Exit code 101 is the leak check. - Slow:
maxon profile run, or--foldedinto a flame graph. - Untested code: build with
--coverageand runmaxon coverage run. - What the compiler emitted:
maxon build --emit-ir.