Skip to content

Commit 2dab95b

Browse files
authored
Preventing "Commands" Command and cleanup (#472)
* Adding a warning to users when they try the 'commands' command via the debug console. * Changing tests infrastructure to have chai globally * Test updates
1 parent 96a5c8f commit 2dab95b

File tree

8 files changed

+53
-15
lines changed

8 files changed

+53
-15
lines changed

.mocharc-windows-ci.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"//": "This timeout should match what is in CdtDebugClient constructor",
3-
"timeout": "25000"
3+
"timeout": "25000",
4+
"require": ["ts-node/register", "src/integration-tests/test/setup.ts"]
45
}

.mocharc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"//": "This timeout should match what is in CdtDebugClient constructor",
3-
"timeout": "5000"
3+
"timeout": "5000",
4+
"require": ["ts-node/register", "src/integration-tests/test/setup.ts"]
45
}

src/gdb/GDBDebugSessionBase.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,14 +2258,17 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
22582258

22592259
if (isCliCommand) {
22602260
const expressionNoPrefix = expression.slice(1).trim();
2261+
const regexCommands = new RegExp(
2262+
'^\\s*(?:comm|comma|comman|command|commands)\\s*.*$'
2263+
);
22612264
const regexDisable = new RegExp(
2262-
'^\\s*(?:dis|disa|disable)\\s*(?:(?:breakpoint|count|delete|once)\\d*)?\\s*\\d*\\s*$'
2265+
'^\\s*(?:dis|disa|disab|disabl|disable)\\s*(?:(?:breakpoint|count|delete|once)\\d*)?\\s*\\d*\\s*$'
22632266
);
22642267
const regexEnable = new RegExp(
2265-
'^\\s*(?:en|enable)\\s*(?:(?:breakpoint|count|delete|once)\\d*)?\\s*\\d*\\s*$'
2268+
'^\\s*(?:en|ena|enab|enabl|enable)\\s*(?:(?:breakpoint|count|delete|once)\\d*)?\\s*\\d*\\s*$'
22662269
);
22672270
const regexDelete = new RegExp(
2268-
'^\\s*(?:d|del|delete)\\s+(?:breakpoints\\s+)?(\\d+)?\\s*$'
2271+
'^\\s*(?:d|de|del|dele|delet|delete)\\s+(?:breakpoints\\s+)?(\\d+)?\\s*$'
22692272
);
22702273
if (
22712274
expressionNoPrefix.search(regexDisable) != -1 ||
@@ -2291,6 +2294,21 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
22912294
);
22922295
}
22932296
}
2297+
if (expressionNoPrefix.search(regexCommands) != -1) {
2298+
this.sendEvent(
2299+
new OutputEvent(
2300+
'warning: "commands" command is not supported via GDB/MI interface',
2301+
'stdout'
2302+
)
2303+
);
2304+
response.body = {
2305+
result: '',
2306+
variablesReference: 0,
2307+
};
2308+
this.sendResponse(response);
2309+
// Avoid sending the command to GDB
2310+
return;
2311+
}
22942312
return await this.evaluateRequestGdbCommand(
22952313
response,
22962314
expressionNoPrefix,

src/integration-tests/auxiliaryGdb.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ import {
2525
import { TargetLaunchRequestArguments } from '../types/session';
2626
import { DebugProtocol } from '@vscode/debugprotocol';
2727
import { hexToBase64 } from '../web';
28-
import * as chai from 'chai';
29-
import * as chaistring from 'chai-string';
3028
import { Runnable } from 'mocha';
31-
chai.use(chaistring);
3229

3330
// This mock adapter creates a standard GDB backend and a stub auxiliary GDB backend
3431
const auxiliaryGdbAdapter =

src/integration-tests/evaluate.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* SPDX-License-Identifier: EPL-2.0
99
*********************************************************************/
1010

11-
import { expect } from 'chai';
1211
import * as path from 'path';
1312
import { CdtDebugClient } from './debugClient';
1413
import {
@@ -21,6 +20,7 @@ import {
2120
standardBeforeEach,
2221
testProgramsDir,
2322
} from './utils';
23+
import { expect } from 'chai';
2424

2525
describe('evaluate request', function () {
2626
let dc: CdtDebugClient;
@@ -97,6 +97,19 @@ describe('evaluate request', function () {
9797
await event;
9898
});
9999

100+
it('should send a warning when the commands command is sent', async function () {
101+
const event = dc.waitForOutputEvent(
102+
'stdout',
103+
'warning: "commands" command is not supported via GDB/MI interface'
104+
);
105+
await dc.evaluateRequest({
106+
context: 'repl',
107+
expression: '> commands',
108+
frameId: scope.frame.id,
109+
});
110+
await event;
111+
});
112+
100113
it('should send a warning when evaluating a delete instruction breakpoint command is sent', async function () {
101114
// set instruction breakpoint
102115
await dc.setInstructionBreakpointsRequest({

src/integration-tests/launchRemoteUnexpectedExit.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ import {
2525
} from './utils';
2626
import { assert, expect } from 'chai';
2727
import { DebugProtocol } from '@vscode/debugprotocol';
28-
import * as chai from 'chai';
29-
import * as chaistring from 'chai-string';
30-
chai.use(chaistring);
3128

3229
describe('launch remote unexpected session exit', function () {
3330
let dc: CdtDebugClient;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*********************************************************************
2+
* Copyright (c) 2025 Arm Limited and others
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*********************************************************************/
10+
11+
import * as chai from 'chai';
12+
import * as chaiString from 'chai-string';
13+
14+
chai.use(chaiString);

src/integration-tests/var.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ import {
2121
verifyRegister,
2222
fillDefaults,
2323
} from './utils';
24-
import * as chai from 'chai';
25-
import * as chaistring from 'chai-string';
26-
chai.use(chaistring);
2724

2825
describe('Variables Test Suite', function () {
2926
let dc: CdtDebugClient;

0 commit comments

Comments
 (0)