Skip to content

Commit

Permalink
add breakpoint modes
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Feb 15, 2024
1 parent b8d3d3a commit 886b1b6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
5 changes: 3 additions & 2 deletions sampleWorkspace/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The text of the markdown is considered the "program to debug" and certain keywor

With the "Run/Debug" split button in the editor header you can easily "run" or "debug" a Markdown file without having to configure a debug configuration.
"Running" a Markdown file has no visible effect. "Debugging" a Markdown file starts the debugger and stops on the first line.

## Stacks

If debugging stops on a line, the line becomes a stack in the CALL STACK with the individual words shown as frames.
Expand Down Expand Up @@ -39,6 +39,7 @@ If a Mock Debug session is active, breakpoints are "validated" according to thes

* if a line is empty or starts with `+` we don't allow to set a breakpoint but move the breakpoint down
* if a line starts with `-` we don't allow to set a breakpoint but move the breakpoint up
* if a line starts with `!`, "hardware" breakpoints can be set on the line
* a breakpoint on a line containing the word `lazy` is not immediately validated, but only after hitting it once.

## Data Breakpoints
Expand Down Expand Up @@ -89,4 +90,4 @@ log(more text in group)
log(end)
````
## The End
## The End
12 changes: 8 additions & 4 deletions src/mockDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ export class MockDebugSession extends LoggingDebugSession {
response.body.supportsFunctionBreakpoints = true;
response.body.supportsDelayedStackTraceLoading = true;

response.body.breakpointModes = [
{ appliesTo: ['source', 'exception'], label: 'Software', mode: 'sw' },
{ appliesTo: ['source', 'exception'], label: 'Hardware', mode: 'hw' },
];

this.sendResponse(response);

// since this debug adapter can accept configuration requests like 'setBreakpoint' at any time,
Expand Down Expand Up @@ -277,19 +282,18 @@ export class MockDebugSession extends LoggingDebugSession {
protected async setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): Promise<void> {

const path = args.source.path as string;
const clientLines = args.lines || [];

// clear all breakpoints for this file
this._runtime.clearBreakpoints(path);

// set and verify breakpoint locations
const actualBreakpoints0 = clientLines.map(async l => {
const { verified, line, id } = await this._runtime.setBreakPoint(path, this.convertClientLineToDebugger(l));
const actualBreakpoints0 = (args.breakpoints || []).map(async ({ line: l, mode }): Promise<DebugProtocol.Breakpoint> => {
const { verified, line, id } = await this._runtime.setBreakPoint(path, this.convertClientLineToDebugger(l), mode);
const bp = new Breakpoint(verified, this.convertDebuggerLineToClient(line)) as DebugProtocol.Breakpoint;
bp.id = id;
return bp;
});
const actualBreakpoints = await Promise.all<DebugProtocol.Breakpoint>(actualBreakpoints0);
const actualBreakpoints = await Promise.all(actualBreakpoints0);

// send back the actual breakpoint positions
response.body = {
Expand Down
12 changes: 8 additions & 4 deletions src/mockRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface IRuntimeBreakpoint {
id: number;
line: number;
verified: boolean;
mode: string; // hw or sw
}

interface IRuntimeStepInTargets {
Expand Down Expand Up @@ -334,10 +335,10 @@ export class MockRuntime extends EventEmitter {
/*
* Set breakpoint in file with given line.
*/
public async setBreakPoint(path: string, line: number): Promise<IRuntimeBreakpoint> {
public async setBreakPoint(path: string, line: number, mode = 'sw'): Promise<IRuntimeBreakpoint> {
path = this.normalizePathAndCasing(path);

const bp: IRuntimeBreakpoint = { verified: false, line, id: this.breakpointId++ };
const bp: IRuntimeBreakpoint = { verified: false, line, id: this.breakpointId++, mode };
let bps = this.breakPoints.get(path);
if (!bps) {
bps = new Array<IRuntimeBreakpoint>();
Expand Down Expand Up @@ -654,13 +655,16 @@ export class MockRuntime extends EventEmitter {
bp.line++;
}
// if a line starts with '-' we don't allow to set a breakpoint but move the breakpoint up
if (srcLine.indexOf('-') === 0) {
if (srcLine.startsWith('-')) {
bp.line--;
}
// don't set 'verified' to true if the line contains the word 'lazy'
// in this case the breakpoint will be verified 'lazy' after hitting it once.
if (srcLine.indexOf('lazy') < 0) {
bp.verified = true;
// if a line starts with '!' we allow setting hardware breakpoints there
if (srcLine.startsWith('!') || bp.mode !== 'hw') {
bp.verified = true;
}
this.sendEvent('breakpointValidated', bp);
}
}
Expand Down

0 comments on commit 886b1b6

Please sign in to comment.