From c8ba46bcc4ca8c9c697af648f349314458d7290e Mon Sep 17 00:00:00 2001 From: Colin Grant Date: Tue, 31 Oct 2023 12:02:35 -0600 Subject: [PATCH] Format --- src/GDBDebugSession.ts | 8 +- .../stepping-granularity.spec.ts | 179 ++++++++++++++---- 2 files changed, 150 insertions(+), 37 deletions(-) diff --git a/src/GDBDebugSession.ts b/src/GDBDebugSession.ts index ab87d7e9..5967869f 100644 --- a/src/GDBDebugSession.ts +++ b/src/GDBDebugSession.ts @@ -1004,7 +1004,9 @@ export class GDBDebugSession extends LoggingDebugSession { args: DebugProtocol.NextArguments ): Promise { try { - await (args.granularity === 'instruction' ? mi.sendExecNextInstruction(this.gdb, args.threadId) : mi.sendExecNext(this.gdb, args.threadId)); + await (args.granularity === 'instruction' + ? mi.sendExecNextInstruction(this.gdb, args.threadId) + : mi.sendExecNext(this.gdb, args.threadId)); this.sendResponse(response); } catch (err) { this.sendErrorResponse( @@ -1020,7 +1022,9 @@ export class GDBDebugSession extends LoggingDebugSession { args: DebugProtocol.StepInArguments ): Promise { try { - await (args.granularity === 'instruction' ? mi.sendExecStepInstruction(this.gdb, args.threadId) : mi.sendExecStep(this.gdb, args.threadId)); + await (args.granularity === 'instruction' + ? mi.sendExecStepInstruction(this.gdb, args.threadId) + : mi.sendExecStep(this.gdb, args.threadId)); this.sendResponse(response); } catch (err) { this.sendErrorResponse( diff --git a/src/integration-tests/stepping-granularity.spec.ts b/src/integration-tests/stepping-granularity.spec.ts index a73f8d00..6ffa19aa 100644 --- a/src/integration-tests/stepping-granularity.spec.ts +++ b/src/integration-tests/stepping-granularity.spec.ts @@ -36,19 +36,19 @@ interface StackStateCheck { instruction: string; } -describe.only('Stepping', async function() { +describe.only('Stepping', async function () { let dc: CdtDebugClient; const steppingProgram = path.join(testProgramsDir, 'stepping'); const steppingSource = path.join(testProgramsDir, 'stepping.c'); - beforeEach(async function() { + beforeEach(async function () { dc = await standardBeforeEach(); await dc.hitBreakpoint( fillDefaults(this.currentTest, { program: steppingProgram }), { path: steppingSource, - line: 8 + line: 8, } ); }); @@ -59,8 +59,12 @@ describe.only('Stepping', async function() { async function getFrameState(threadId: number) { const stack = await dc.stackTraceRequest({ threadId }); - const main = stack.body.stackFrames.find(frame => frame.name === 'main'); - const elsewhere = stack.body.stackFrames.find(frame => frame.name === 'getFromElsewhere'); + const main = stack.body.stackFrames.find( + (frame) => frame.name === 'main' + ); + const elsewhere = stack.body.stackFrames.find( + (frame) => frame.name === 'getFromElsewhere' + ); return { main, elsewhere }; } @@ -72,58 +76,163 @@ describe.only('Stepping', async function() { } const target = check.elsewhereDefined ? 'elsewhere' : 'main'; expect(state[target]).not.to.be.undefined; - expect(state[target]?.line).equal(check.line, `It should have stopped at line ${check.line}`); - expect(state[target]?.instructionPointerReference).equal(check.instruction, `It should have stopped here in ${target}!`); + expect(state[target]?.line).equal( + check.line, + `It should have stopped at line ${check.line}` + ); + expect(state[target]?.instructionPointerReference).equal( + check.instruction, + `It should have stopped here in ${target}!` + ); } it('steps in by line', async () => { const threads = await dc.threadsRequest(); const threadId = threads.body.threads[0].id; - expectStackState(await getFrameState(threadId), { elsewhereDefined: false, line: 8, instruction: '0x00000000004005bc' }); - await Promise.all([dc.stepInRequest({ threadId, granularity: 'statement' }), dc.waitForEvent('stopped')]); - expectStackState(await getFrameState(threadId), { elsewhereDefined: true, line: 15, instruction: '0x0000000000400600' }); - await Promise.all([dc.stepInRequest({ threadId, granularity: 'statement' }), dc.waitForEvent('stopped')]); - expectStackState(await getFrameState(threadId), { elsewhereDefined: true, line: 16, instruction: '0x0000000000400606' }); + expectStackState(await getFrameState(threadId), { + elsewhereDefined: false, + line: 8, + instruction: '0x00000000004005bc', + }); + await Promise.all([ + dc.stepInRequest({ threadId, granularity: 'statement' }), + dc.waitForEvent('stopped'), + ]); + expectStackState(await getFrameState(threadId), { + elsewhereDefined: true, + line: 15, + instruction: '0x0000000000400600', + }); + await Promise.all([ + dc.stepInRequest({ threadId, granularity: 'statement' }), + dc.waitForEvent('stopped'), + ]); + expectStackState(await getFrameState(threadId), { + elsewhereDefined: true, + line: 16, + instruction: '0x0000000000400606', + }); }); it('steps in by instruction', async () => { const threads = await dc.threadsRequest(); const threadId = threads.body.threads[0].id; - expectStackState(await getFrameState(threadId), { elsewhereDefined: false, line: 8, instruction: '0x00000000004005bc' }); - await Promise.all([dc.stepInRequest({ threadId, granularity: 'instruction' }), dc.waitForEvent('stopped')]); + expectStackState(await getFrameState(threadId), { + elsewhereDefined: false, + line: 8, + instruction: '0x00000000004005bc', + }); + await Promise.all([ + dc.stepInRequest({ threadId, granularity: 'instruction' }), + dc.waitForEvent('stopped'), + ]); // First step should not take us straight to the function. - expectStackState(await getFrameState(threadId), { elsewhereDefined: false, line: 8, instruction: '0x00000000004005c0' }); + expectStackState(await getFrameState(threadId), { + elsewhereDefined: false, + line: 8, + instruction: '0x00000000004005c0', + }); // Step several times to get into the function. - await Promise.all([dc.stepInRequest({ threadId, granularity: 'instruction' }), dc.waitForEvent('stopped')]); - await Promise.all([dc.stepInRequest({ threadId, granularity: 'instruction' }), dc.waitForEvent('stopped')]); - await Promise.all([dc.stepInRequest({ threadId, granularity: 'instruction' }), dc.waitForEvent('stopped')]); - expectStackState(await getFrameState(threadId), { elsewhereDefined: true, line: 14, instruction: '0x00000000004005f5' }); + await Promise.all([ + dc.stepInRequest({ threadId, granularity: 'instruction' }), + dc.waitForEvent('stopped'), + ]); + await Promise.all([ + dc.stepInRequest({ threadId, granularity: 'instruction' }), + dc.waitForEvent('stopped'), + ]); + await Promise.all([ + dc.stepInRequest({ threadId, granularity: 'instruction' }), + dc.waitForEvent('stopped'), + ]); + expectStackState(await getFrameState(threadId), { + elsewhereDefined: true, + line: 14, + instruction: '0x00000000004005f5', + }); }); it('steps next by line and skips a function', async () => { const threads = await dc.threadsRequest(); const threadId = threads.body.threads[0].id; - expectStackState(await getFrameState(threadId), { elsewhereDefined: false, line: 8, instruction: '0x00000000004005bc' }); - await Promise.all([dc.nextRequest({ threadId, granularity: 'statement' }), dc.waitForEvent('stopped')]); - expectStackState(await getFrameState(threadId), { elsewhereDefined: false, line: 9, instruction: '0x00000000004005cf' }); - await Promise.all([dc.nextRequest({ threadId, granularity: 'statement' }), dc.waitForEvent('stopped')]); - expectStackState(await getFrameState(threadId), { elsewhereDefined: false, line: 6, instruction: '0x00000000004005e4' }); + expectStackState(await getFrameState(threadId), { + elsewhereDefined: false, + line: 8, + instruction: '0x00000000004005bc', + }); + await Promise.all([ + dc.nextRequest({ threadId, granularity: 'statement' }), + dc.waitForEvent('stopped'), + ]); + expectStackState(await getFrameState(threadId), { + elsewhereDefined: false, + line: 9, + instruction: '0x00000000004005cf', + }); + await Promise.all([ + dc.nextRequest({ threadId, granularity: 'statement' }), + dc.waitForEvent('stopped'), + ]); + expectStackState(await getFrameState(threadId), { + elsewhereDefined: false, + line: 6, + instruction: '0x00000000004005e4', + }); }); it('steps next by instruction and skips a function', async () => { const threads = await dc.threadsRequest(); const threadId = threads.body.threads[0].id; - expectStackState(await getFrameState(threadId), { elsewhereDefined: false, line: 8, instruction: '0x00000000004005bc' }); + expectStackState(await getFrameState(threadId), { + elsewhereDefined: false, + line: 8, + instruction: '0x00000000004005bc', + }); // Step several times to prove that we go straight from 8 to 9. - await Promise.all([dc.nextRequest({ threadId, granularity: 'instruction' }), dc.waitForEvent('stopped')]); - expectStackState(await getFrameState(threadId), { elsewhereDefined: false, line: 8, instruction: '0x00000000004005c0' }); - await Promise.all([dc.nextRequest({ threadId, granularity: 'instruction' }), dc.waitForEvent('stopped')]); - expectStackState(await getFrameState(threadId), { elsewhereDefined: false, line: 8, instruction: '0x00000000004005c2' }); - await Promise.all([dc.nextRequest({ threadId, granularity: 'instruction' }), dc.waitForEvent('stopped')]); - expectStackState(await getFrameState(threadId), { elsewhereDefined: false, line: 8, instruction: '0x00000000004005c7' }); - await Promise.all([dc.nextRequest({ threadId, granularity: 'instruction' }), dc.waitForEvent('stopped')]); - expectStackState(await getFrameState(threadId), { elsewhereDefined: false, line: 8, instruction: '0x00000000004005cc' }); - await Promise.all([dc.nextRequest({ threadId, granularity: 'instruction' }), dc.waitForEvent('stopped')]); - expectStackState(await getFrameState(threadId), { elsewhereDefined: false, line: 9, instruction: '0x00000000004005cf' }); + await Promise.all([ + dc.nextRequest({ threadId, granularity: 'instruction' }), + dc.waitForEvent('stopped'), + ]); + expectStackState(await getFrameState(threadId), { + elsewhereDefined: false, + line: 8, + instruction: '0x00000000004005c0', + }); + await Promise.all([ + dc.nextRequest({ threadId, granularity: 'instruction' }), + dc.waitForEvent('stopped'), + ]); + expectStackState(await getFrameState(threadId), { + elsewhereDefined: false, + line: 8, + instruction: '0x00000000004005c2', + }); + await Promise.all([ + dc.nextRequest({ threadId, granularity: 'instruction' }), + dc.waitForEvent('stopped'), + ]); + expectStackState(await getFrameState(threadId), { + elsewhereDefined: false, + line: 8, + instruction: '0x00000000004005c7', + }); + await Promise.all([ + dc.nextRequest({ threadId, granularity: 'instruction' }), + dc.waitForEvent('stopped'), + ]); + expectStackState(await getFrameState(threadId), { + elsewhereDefined: false, + line: 8, + instruction: '0x00000000004005cc', + }); + await Promise.all([ + dc.nextRequest({ threadId, granularity: 'instruction' }), + dc.waitForEvent('stopped'), + ]); + expectStackState(await getFrameState(threadId), { + elsewhereDefined: false, + line: 9, + instruction: '0x00000000004005cf', + }); }); });