microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.44k stars 28.62k forks source link

What's the id of debugProtocol.Breakpoint when the reason is removed? #113494

Closed Abbyyan closed 3 years ago

Abbyyan commented 3 years ago

When the breakpoint command can't be solved with my debuggers, I want to remove it from vscode UI(That is to say, remove the red dot on vscode editor automatically). So i try to use the BreakpointEvent with reason removed . But it really confused me how to set the id of the id of Breakpoint. Does it increase by one according to the click event on vsocde UI or returned from my debugger please? Hope for your help. Thanks a lot.

Abbyyan commented 3 years ago

Seen from https://github.com/microsoft/vscode-mock-debug/blob/85f04c5ae88a592098ce64008872500026d2a691/src/mockRuntime.ts#L216 , it seems like the id is just a increasing number? Is there any misunderstanding here please? Hope for your help. Thanks a lot.

weinand commented 3 years ago

When the DA creates a breakpoint based on the setBreakpoints request, it can optionally give the new breakpoint an ID (and return it from the setBreakpoints request). The client (e.g. VS Code) will store the ID without interpreting it. Later when the breakpoint should be removed, the DA must use the same ID.

Mock Debug shows how to use "ID" with the "breakpoint" request.

Abbyyan commented 3 years ago

In function protected setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments) Should i send break-insert command to my debugger according to args (Which contains the breakpoints added in the client ,eg vscode ), get theresult (returned from debugger) and add a id to the result, then send the response to vscode . After that the id will be stored and can use when removed? Does the id will worked only after sendResponse? In my case, the addBreakPoint may result error, If this happends, i want to remove the breakpoint on the vsocde UI.

function setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): void {

    const cb = (() => {
        this.debugReady = true;
        let path = args.source.path;

        const all = args.breakpoints.map(brk => {
            return this.myDebugger.addBreakPoint({ file: path, line: brk.line, condition: brk.condition, countCondition: brk.hitCondition });
        });
        Promise.all(all).then(brkpoints => {
            const finalBrks = [];
            brkpoints.forEach(brkp => {
                const bt = new DebugAdapter.Breakpoint(true, brkp[1].line);
                bt.id = this.count++; // give it a unique id
                finalBrks.push(bt);
            });
            response.body = {
                breakpoints: finalBrks
            };
            this.sendResponse(response); // Does the id will worked only after sendResponse?

        }, msg => {
            this.sendErrorResponse(response, 9, msg.toString());
        });

    }).bind(this);
    if (this.debugReady)
        cb();
    else
        this.myDebugger.once("debug-ready", cb);
}
Abbyyan commented 3 years ago

When the DA creates a breakpoint based on the setBreakpoints request, it can optionally give the new breakpoint an ID (and return it from the setBreakpoints request). The client (e.g. VS Code) will store the ID without interpreting it. Later when the breakpoint should be removed, the DA must use the same ID.

Mock Debug shows how to use "ID" with the "breakpoint" request.

Does it mean the vscode UI will update according to the SetBreakpointsResponse ? But in my experiment, the breakpoint on the vscode UI won't be removed even i delete some elements in SetBreakpointsResponse. Could you please explain which is the breakpoint send to vscode UI if possible? Thanks a lot.

Abbyyan commented 3 years ago

When the DA creates a breakpoint based on the setBreakpoints request, it can optionally give the new breakpoint an ID (and return it from the setBreakpoints request). The client (e.g. VS Code) will store the ID without interpreting it. Later when the breakpoint should be removed, the DA must use the same ID.

Mock Debug shows how to use "ID" with the "breakpoint" request.

My goal is send the breakpoint info to my debugger in setBreakPointsRequest and set the breakpoint in debugger. But if the debugger fails to deal with a breakpoint , remove the breakpoint (the red dot) on the vscode UI. In my understanding, i should deal with the breakpoint and add a id to the breakpoint in the DebugProtocol.SetBreakpointsArguments even if the breakpoint fails to set in my debugger. Then add it into DebugProtocol.SetBreakpointsResponse and send to vscode UI. If the breakpoint fails to set, remove it using BreakpointEvent with reason removed.

Or the breakpoints send to SetBreakpointsResponse will be activated in the vscode. That is to say, if i run into a failed breakpoint , vscode will still stop at the breakpoint? Is there any problem with my understanding please? Thanks a lot.

Abbyyan commented 3 years ago

Got it. Thanks a lot.