Skip to content

probe-web / @probe-web/client / index / Debugger

Class: Debugger ​

Defined in: debugger.ts:353

Run control and inspection for one core: pause, continue, step, reset, breakpoints, stack traces, scopes and variables, registers and memory, plus RTT and semihosting output while debugging. Get one from Session.debugger.

Calls are serialised, so they can be issued from anywhere without interleaving. Frame ids and variable references belong to one stop: once the core resumes (Debugger.epoch changes) they are rejected with kind: 'stale-reference'.

Events (all CustomEvents; call Debugger.start to have them fire on their own):

  • stopped — the core halted; detail is a StoppedDetail.
  • continued — the core is running again.
  • state — any change of RunState; detail is the new state.
  • locked-up — the core locked up.
  • breakpoints — the breakpoint list changed; detail is every Breakpoint.
  • output — RTT or semihosting text; detail is a DebugOutput.
  • rtt-bytes — data from a binary RTT channel; detail is an RttBytes.
  • error — the status poller failed; detail is the error.

Example ​

ts
const dbg = session.debugger();
dbg.addEventListener('stopped', async () => {
  const [frame] = await dbg.stackTrace();
  const scopes = await dbg.scopes(frame.id);
  const locals = scopes.find((s) => s.name === 'Variables');
  if (locals) console.log(frame.functionName, await dbg.variables(locals.reference));
});
dbg.start();
await dbg.loadDebugInfo(elfBytes, 'app.elf');
await dbg.setSourceBreakpoints('src/main.rs', [{ line: 42 }]);
await dbg.resetAndHalt();
await dbg.continue();
// later
await dbg.step('over');
dbg.dispose();

Extends ​

  • EventTarget

Constructors ​

Constructor ​

ts
new Debugger(session, options?): Debugger;

Defined in: debugger.ts:387

Apps normally use Session.debugger; tests can pass a fake session here.

Parameters ​

ParameterType
sessionDebugSessionLike
optionsDebuggerOptions

Returns ​

Debugger

Overrides ​

ts
EventTarget.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionDefined in
sessionreadonlyDebugSessionLikeundefinedThe session this debugger drives.debugger.ts:355
coreIndexreadonlynumberundefinedIndex of the core it controls.debugger.ts:357
corereadonlyDebugCoreLikeundefinedThat core.debugger.ts:359
epochpublicnumber0Increments whenever the core resumes; results tied to a stop carry it.debugger.ts:369
statepublicRunState'unknown'The core's state as last seen (by the poller, or by the debugger's own calls).debugger.ts:382
lastStoppublicStoppedDetail | nullnullThe current stop, or null while the core is not halted.debugger.ts:384

Accessors ​

canDisassemble ​

Get Signature ​

ts
get canDisassemble(): boolean;

Defined in: debugger.ts:1023

Whether this connection can disassemble. probe-rs serve can; the WebUSB worker cannot (probe-rs uses capstone, which is C code). Views should show that instead of an error.

Returns ​

boolean

Methods ​

refresh() ​

ts
refresh(): Promise<RunState>;

Defined in: debugger.ts:448

Current status, read now (not from the poller).

Returns ​

Promise<RunState>


start() ​

ts
start(): void;

Defined in: debugger.ts:469

Start polling core/status (idempotent). Stops on dispose().

Returns ​

void


dispose() ​

ts
dispose(): void;

Defined in: debugger.ts:490

Stop the poller. The debugger does not detach or resume the core.

Returns ​

void


registerTable() ​

ts
registerTable(): Promise<RegisterInfo[]>;

Defined in: debugger.ts:521

Register names, ids and widths for this core.

Returns ​

Promise<RegisterInfo[]>


pause() ​

ts
pause(): Promise<StoppedDetail>;

Defined in: debugger.ts:528

Halt; emits stopped with reason Request.

Returns ​

Promise<StoppedDetail>


continue() ​

ts
continue(): Promise<void>;

Defined in: debugger.ts:537

Resume. Clears the server's per-core debug state first, so no stale frame or variable ids survive.

Returns ​

Promise<void>


step() ​

ts
step(mode): Promise<{
  pc: bigint;
  warning: string | null;
}>;

Defined in: debugger.ts:551

Step (instruction needs no debug info; the others need loadDebugInfo). Emits stopped with reason Step. Resolves with the new program counter and, when the step did not go exactly as asked (e.g. step out timed out before reaching the caller), a warning to show the user.

Parameters ​

ParameterType
modeSteppingMode

Returns ​

Promise<{ pc: bigint; warning: string | null; }>


reset() ​

ts
reset(): Promise<void>;

Defined in: debugger.ts:664

Reset and keep running. Breakpoints are armed again (see resetAndHalt).

Returns ​

Promise<void>


resetAndHalt() ​

ts
resetAndHalt(): Promise<StoppedDetail>;

Defined in: debugger.ts:690

Reset and halt at the reset vector; emits stopped. Breakpoints are armed again afterwards: a reset clears the hardware comparators on some targets (MCX family, ESP32-S3).

Returns ​

Promise<StoppedDetail>


enableVectorCatch() ​

ts
enableVectorCatch(condition): Promise<void>;

Defined in: debugger.ts:709

Halt the core when it takes this exception (e.g. HardFault, CoreReset).

Parameters ​

ParameterType
conditionWireVectorCatchCondition

Returns ​

Promise<void>


loadDebugInfo() ​

ts
loadDebugInfo(elf, name?): Promise<void>;

Defined in: debugger.ts:717

Upload an ELF (content-hash cached on the server) and load its DWARF. Needed for statement stepping, source breakpoints, stack traces with names, and every variables query.

Parameters ​

ParameterTypeDefault value
elfUint8Arrayundefined
namestring'firmware.elf'

Returns ​

Promise<void>


loadSvd() ​

ts
loadSvd(svd, name?): Promise<void>;

Defined in: debugger.ts:730

Load a CMSIS-SVD file; its peripherals appear as the Peripherals scope.

Parameters ​

ParameterTypeDefault value
svdUint8Arrayundefined
namestring'device.svd'

Returns ​

Promise<void>


clearSvd() ​

ts
clearSvd(): Promise<void>;

Defined in: debugger.ts:735

Unload the SVD, removing the Peripherals scope.

Returns ​

Promise<void>


stackTrace() ​

ts
stackTrace(limit?): Promise<Frame[]>;

Defined in: debugger.ts:775

Stack frames of the current stop (taken once per stop, then cached). The core must be halted.

Parameters ​

ParameterTypeDefault value
limitnumber200

Returns ​

Promise<Frame[]>


scopes() ​

ts
scopes(frameId): Promise<Scope[]>;

Defined in: debugger.ts:792

Scopes of a frame: Static, Peripherals (with an SVD), Registers, Variables.

Parameters ​

ParameterType
frameIdnumber

Returns ​

Promise<Scope[]>


variables() ​

ts
variables(reference, filter?): Promise<Variable[]>;

Defined in: debugger.ts:807

Children of a scope or variable. filter: indexed or named to page large aggregates.

Parameters ​

ParameterType
referencenumber
filter?"indexed" | "named"

Returns ​

Promise<Variable[]>


evaluate() ​

ts
evaluate(expression, frameId?): Promise<Evaluation>;

Defined in: debugger.ts:831

Look up a register, a variable in the frame, or a static by name (probe-rs has no expression parser).

Parameters ​

ParameterType
expressionstring
frameId?number

Returns ​

Promise<Evaluation>


setVariable() ​

ts
setVariable(variable, value): Promise<Evaluation>;

Defined in: debugger.ts:844

Write a variable's value (parsed by probe-rs for the variable's type). Registers: use writeRegister.

Parameters ​

ParameterType
variablePick<Variable, "name" | "parent">
valuestring

Returns ​

Promise<Evaluation>


breakpoints() ​

ts
breakpoints(): Breakpoint[];

Defined in: debugger.ts:867

Every breakpoint, source then instruction.

Returns ​

Breakpoint[]


setSourceBreakpoints() ​

ts
setSourceBreakpoints(path, specs): Promise<Breakpoint[]>;

Defined in: debugger.ts:936

Replace the breakpoints in one source file (as DAP setBreakpoints does). path may be the absolute build path or a relative suffix such as src/main.rs. Needs debug info.

Parameters ​

ParameterType
pathstring
specs{ line: number; column?: number; }[]

Returns ​

Promise<Breakpoint[]>


setInstructionBreakpoints() ​

ts
setInstructionBreakpoints(addresses): Promise<Breakpoint[]>;

Defined in: debugger.ts:949

Replace all instruction (address) breakpoints.

Parameters ​

ParameterType
addresses(number | bigint)[]

Returns ​

Promise<Breakpoint[]>


clearBreakpoints() ​

ts
clearBreakpoints(): Promise<void>;

Defined in: debugger.ts:974

Remove every breakpoint from the target.

Returns ​

Promise<void>


reapplyBreakpoints() ​

ts
reapplyBreakpoints(): Promise<Breakpoint[]>;

Defined in: debugger.ts:989

Set every breakpoint again: after loading a new ELF (source lines may map elsewhere) or on targets that lose comparators on reset (MCX family, ESP32-S3); reset/resetAndHalt call it.

Returns ​

Promise<Breakpoint[]>


resolveSourceLocations() ​

ts
resolveSourceLocations(addresses): Promise<(SourceLocation | null)[]>;

Defined in: debugger.ts:1011

Source locations for addresses (null where there is no line information).

Parameters ​

ParameterType
addresses(number | bigint)[]

Returns ​

Promise<(SourceLocation | null)[]>


disassemble() ​

ts
disassemble(
   address, 
   count, 
   instructionOffset?, 
   byteOffset?
): Promise<Instruction[]>;

Defined in: debugger.ts:1032

Disassemble count instructions starting at address shifted by instructionOffset instructions (negative looks backwards, as DAP disassemble does). Needs probe-rs serve: over WebUSB it rejects with kind: 'unsupported' (see Debugger.canDisassemble).

Parameters ​

ParameterTypeDefault value
addressnumber | bigintundefined
countnumberundefined
instructionOffsetnumber0
byteOffsetnumber0

Returns ​

Promise<Instruction[]>


enableRtt() ​

ts
enableRtt(options?): Promise<void>;

Defined in: debugger.ts:1057

Show the firmware's RTT output while debugging: creates an RTT client (with an exact scan region when elf links _SEGGER_RTT) and polls its up channels whenever the poller runs (start()); output arrives as output events. Semihosting output is reported the same way without calling this.

Parameters ​

ParameterType
options{ elf?: Uint8Array<ArrayBufferLike>; channels?: RttChannelConfigInput[]; }
options.elf?Uint8Array<ArrayBufferLike>
options.channels?RttChannelConfigInput[]

Returns ​

Promise<void>


pollRtt() ​

ts
pollRtt(): Promise<void>;

Defined in: debugger.ts:1068

Read RTT once now (the poller does this while the core runs).

Returns ​

Promise<void>


readRegisters() ​

ts
readRegisters(): Promise<RegisterValue[]>;

Defined in: debugger.ts:1118

Read every register in the table; registers the core does not have are left out.

Returns ​

Promise<RegisterValue[]>


writeRegister() ​

ts
writeRegister(register, value): Promise<void>;

Defined in: debugger.ts:1133

Write a register by name (case-insensitive) or id. The core must be halted.

Parameters ​

ParameterType
registerstring | number
valuebigint

Returns ​

Promise<void>


readMemory() ​

ts
readMemory(address, count): Promise<Uint8Array<ArrayBufferLike>>;

Defined in: debugger.ts:1145

Read up to count bytes; a shorter result means the rest is unreadable.

Parameters ​

ParameterType
addressnumber | bigint
countnumber

Returns ​

Promise<Uint8Array<ArrayBufferLike>>


writeMemory() ​

ts
writeMemory(address, data): Promise<void>;

Defined in: debugger.ts:1150

Write bytes starting at address.

Parameters ​

ParameterType
addressnumber | bigint
dataUint8Array

Returns ​

Promise<void>