Skip to content

Commit 368383e

Browse files
committed
Added overridePreEndSessionCommands, and try 'monitor exit' before target-disconnect first
1 parent d004e9d commit 368383e

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

package.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.13.0-pre6",
2+
"version": "1.13.0-pre7",
33
"preview": false,
44
"activationEvents": [
55
"onDebugResolve:cortex-debug",
@@ -628,6 +628,12 @@
628628
"deprecated": true,
629629
"description": "Deprecated: Restart is now handled by VSCode and it is pretty much the same as Start"
630630
},
631+
"overridePreEndSessionCommands": {
632+
"default": [],
633+
"type": "array",
634+
"items": "string",
635+
"description": "Override the commands that are normally executed at the start of ending a debug session (e.g. when stopping debugging)."
636+
},
631637
"overrideGDBServerStartedRegex": {
632638
"description": "You can supply a regular expression (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions) in the configuration property to override the output from the GDB Server that is looked for to determine if the GDB Server has started. Under most circumstances this will not be necessary - but could be needed as a result of a change in the output of a GDB Server making it incompatible with cortex-debug. This property has no effect for bmp or external GDB Server types.",
633639
"type": "string",
@@ -1761,6 +1767,12 @@
17611767
"items": "string",
17621768
"description": "Additional GDB Commands to be executed at the end of the reset sequence"
17631769
},
1770+
"overridePreEndSessionCommands": {
1771+
"default": [],
1772+
"type": "array",
1773+
"items": "string",
1774+
"description": "Override the commands that are normally executed at the start of ending a debug session (e.g. when stopping debugging)."
1775+
},
17641776
"overrideGDBServerStartedRegex": {
17651777
"description": "You can supply a regular expression (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions) in the configuration property to override the output from the GDB Server that is looked for to determine if the GDB Server has started. Under most circumstances this will not be necessary - but could be needed as a result of a change in the output of a GDB Server making it incompatible with cortex-debug. This property has no effect for bmp or external GDB Server types.",
17661778
"type": "string",

src/backend/mi2/mi2.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ export class MI2 extends EventEmitter implements IBackend {
403403
}
404404
}
405405

406-
// stop() can get called twice ... once by the disconnect sequence and once by the server existing because
406+
// stop() can get called twice ... once by the disconnect sequence and once by the server exiting because
407407
// we called disconnect. And the sleeps don't help that cause
408408
private exiting = false;
409409
public async stop() {
@@ -439,8 +439,16 @@ export class MI2 extends EventEmitter implements IBackend {
439439
// program is in paused state
440440
try {
441441
startKillTimeout(500);
442-
await new Promise((res) => setTimeout(res, 100)); // For some people delay was needed. Doesn't hurt I guess
443-
await this.sendCommand('target-disconnect'); // Yes, this can fail
442+
try {
443+
await this.sendCommand('interpreter-exec console "monitor exit"');
444+
} catch (e) {
445+
// It is possible gdb server has not implemented this
446+
ServerConsoleLog('GDB "monitor exit" failed, continue to disconnect anyway', this.pid);
447+
}
448+
await new Promise(() => setTimeout(() => {}, 50)); // For some people delay was needed. Doesn't hurt I guess
449+
if (!this.exited) {
450+
await this.sendCommand('target-disconnect'); // Yes, this can fail
451+
}
444452
} catch (e) {
445453
if (this.exited) {
446454
ServerConsoleLog('GDB already exited during a target-disconnect', this.pid);

src/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ export interface ConfigurationArguments extends DebugProtocol.LaunchRequestArgum
270270
loadFiles: string[];
271271
symbolFiles: SymbolFile[];
272272
debuggerArgs: string[];
273+
overridePreEndSessionCommands: null | string[];
273274
preLaunchCommands: string[];
274275
postLaunchCommands: string[];
275276
overrideLaunchCommands: string[];

src/frontend/configprovider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export class CortexDebugConfigurationProvider implements vscode.DebugConfigurati
130130
if (!config.postAttachCommands) { config.postAttachCommands = []; }
131131
if (!config.preResetCommands) { config.preResetCommands = config.preRestartCommands || []; }
132132
if (!config.postResetCommands) { config.postResetCommands = config.postRestartCommands || []; }
133+
if (config.overridePreEndSessionCommands === undefined) { config.overridePreEndSessionCommands = null; }
133134
if (!config.postResetSessionCommands) { config.postResetSessionCommands = config.postRestartSessionCommands || null; }
134135
if (config.runToEntryPoint) { config.runToEntryPoint = config.runToEntryPoint.trim(); } else if (config.runToMain) {
135136
config.runToEntryPoint = 'main';

src/gdb.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,20 @@ export class GDBDebugSession extends LoggingDebugSession {
333333
response.body.supportsInstructionBreakpoints = true;
334334
response.body.supportsReadMemoryRequest = true;
335335
response.body.supportsWriteMemoryRequest = true;
336+
337+
const bptAppliesTo: DebugProtocol.BreakpointModeApplicability[] = ['source', /* 'exception' , */ 'data', 'instruction'];
338+
response.body.breakpointModes = [
339+
{
340+
mode: 'default',
341+
label: 'Let GDB decide which breakpoint method (HW or SW) to chose',
342+
appliesTo: []
343+
},
344+
{
345+
mode: 'hardware',
346+
label: 'Request GDB to set a hardware breakpoint',
347+
appliesTo: []
348+
}
349+
];
336350
this.sendResponse(response);
337351
}
338352

@@ -1475,7 +1489,7 @@ export class GDBDebugSession extends LoggingDebugSession {
14751489
}
14761490

14771491
private waitForServerExitAndRespond(response: DebugProtocol.DisconnectResponse) {
1478-
if (!this.server.isExternal()) {
1492+
if (!this.server.isExternal() && this.server.isProcessRunning()) {
14791493
let nTimes = 60;
14801494
let to = setInterval(() => {
14811495
if ((nTimes === 0) || this.quit) {
@@ -1499,11 +1513,14 @@ export class GDBDebugSession extends LoggingDebugSession {
14991513
}
15001514
});
15011515
// Note: If gdb exits first, then we kill the server anyways
1502-
} else {
1516+
} else if (this.miDebugger.isRunning()) {
15031517
this.miDebugger.once('quit', () => {
15041518
this.serverConsoleLog('disconnectRequest sendResponse 1');
15051519
this.sendResponse(response);
15061520
});
1521+
} else {
1522+
this.serverConsoleLog('disconnectRequest sendResponse 3');
1523+
this.sendResponse(response);
15071524
}
15081525
}
15091526

@@ -1563,6 +1580,16 @@ export class GDBDebugSession extends LoggingDebugSession {
15631580
await this.tryDeleteBreakpoints();
15641581
this.disableSendStoppedEvents = false;
15651582
this.attached = false;
1583+
if (this.args.overridePreEndSessionCommands) {
1584+
for (const cmd of this.args.overridePreEndSessionCommands) {
1585+
try {
1586+
await this.miDebugger.sendCommand(cmd);
1587+
} catch (e) {
1588+
this.handleMsg('log', 'GDB commands overridePreEndSessionCommands failed ' + (e ? e.toString() : 'Unknown error') + '\n');
1589+
}
1590+
}
1591+
await new Promise(() => setTimeout(() => {}, 5));
1592+
}
15661593
this.waitForServerExitAndRespond(response); // Will wait asynchronously until the following actions are done
15671594
if (args.terminateDebuggee || args.suspendDebuggee) {
15681595
// There is no such thing as terminate for us. Hopefully, the gdb-server will

0 commit comments

Comments
 (0)