Skip to content

Commit

Permalink
Add some debug output to the OpenOCD server controller.
Browse files Browse the repository at this point in the history
This will help to diagnose issues with the OpenOCD server controller.
  • Loading branch information
hulryung committed May 21, 2024
1 parent 23d49a2 commit 8b2978c
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 1,023 deletions.
5 changes: 0 additions & 5 deletions src/frontend/configprovider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as vscode from 'vscode';
import * as fs from 'fs';
import * as os from 'os';
import { STLinkServerController } from './../stlink';
import { GDBServerConsole } from './server_console';
import { ADAPTER_DEBUG_MODE, ChainedConfigurations, ChainedEvents, CortexDebugKeys, sanitizeDevDebug, ConfigurationArguments, validateELFHeader, SymbolFile, defSymbolFile } from '../common';
import { CDebugChainedSessionItem, CDebugSession } from './cortex_debug_session';
Expand Down Expand Up @@ -166,10 +165,6 @@ export class CortexDebugConfigurationProvider implements vscode.DebugConfigurati
this.setOsSpecficConfigSetting(config, 'toolchainPath', 'armToolchainPath');

if (!config.toolchainPath) {
// Special case to auto-resolve GCC toolchain for STM32CubeIDE users
if (!config.armToolchainPath && config.servertype === 'stlink') {
config.armToolchainPath = STLinkServerController.getArmToolchainPath();
}
}

if (!config.toolchainPrefix) {
Expand Down
31 changes: 12 additions & 19 deletions src/gdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,8 @@ import * as crypto from 'crypto';

import { setTimeout } from 'timers';
import { EventEmitter } from 'events';

import { JLinkServerController } from './jlink';
import { OpenOCDServerController } from './openocd';
import { STUtilServerController } from './stutil';
import { STLinkServerController } from './stlink';
import { PyOCDServerController } from './pyocd';
import { BMPServerController } from './bmp';
import { PEServerController } from './pemicro';
import { QEMUServerController } from './qemu';
import { ExternalServerController } from './external';

import { SymbolTable } from './backend/symbols';
import { SymbolInformation, SymbolScope } from './symbols';
import { TcpPortScanner } from './tcpportscanner';
Expand Down Expand Up @@ -79,15 +71,8 @@ if (false) {
}

const SERVER_TYPE_MAP = {
jlink: JLinkServerController,
openocd: OpenOCDServerController,
stutil: STUtilServerController,
stlink: STLinkServerController,
pyocd: PyOCDServerController,
pe: PEServerController,
bmp: BMPServerController,
qemu: QEMUServerController,
external: ExternalServerController
openocd: OpenOCDServerController

};

// Type of session start. Also used in display of call-stack window
Expand Down Expand Up @@ -270,6 +255,7 @@ export class GDBDebugSession extends LoggingDebugSession {

public constructor(debuggerLinesStartAt1: boolean, public readonly isServer: boolean = false, threadID: number = 1) {
super(undefined, debuggerLinesStartAt1, isServer); // Use if deriving from LogDebugSession
console.log('GDBDebugSession constructor');
// super(debuggerLinesStartAt1, isServer); // Use if deriving from DebugSession

// TcpPortScanner.PortAllocated.on('allocated', (ports) => {
Expand Down Expand Up @@ -548,7 +534,7 @@ export class GDBDebugSession extends LoggingDebugSession {
return doResolve();
}

const ControllerClass = SERVER_TYPE_MAP[this.args.servertype];
const ControllerClass = OpenOCDServerController;
this.serverController = new ControllerClass();
this.serverController.setArguments(this.args);
this.serverController.on('event', this.serverControllerEvent.bind(this));
Expand Down Expand Up @@ -1085,17 +1071,21 @@ export class GDBDebugSession extends LoggingDebugSession {
}

protected async customRequest(command: string, response: DebugProtocol.Response, args: any) {
this.handleMsg('log', `Custom request ${command}\n`);
const retFunc = () => {
this.sendErrorResponse(response, 110, `Custom request ${command} cannot be run now, because debugger is busy}`,
undefined, ErrorDestination.Telemetry);
return;
};
this.handleMsg('log', `Custom request ${command}\n`);

if (this.serverController.customRequest(command, response, args)) {
this.handleMsg('log', `Custom request ${command} handled by server controller\n`);
return retFunc();
}

const isBusy = !this.stopped || this.continuing || !this.isMIStatusStopped();
this.handleMsg('log', `Custom request ${command} isBusy=${isBusy}\n`);
switch (command) {
case 'liveEvaluate':
if (this.miLiveGdb) {
Expand Down Expand Up @@ -1205,7 +1195,10 @@ export class GDBDebugSession extends LoggingDebugSession {
this.sendResponse(response);
break;
case 'rtt-poll': {
this.handleMsg('log', '(customRequest) rtt-poll\n');
if (this.serverController.rttPoll) {
this.handleMsg('log', `${this.serverController.name}: rttPoll\n`);
this.handleMsg('log', '(customRequest) serverController.rttPoll\n');
this.serverController.rttPoll();
}
break;
Expand Down
227 changes: 0 additions & 227 deletions src/jlink.ts

This file was deleted.

7 changes: 5 additions & 2 deletions src/openocd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as fs from 'fs';
import * as net from 'net';
import * as path from 'path';
import { EventEmitter } from 'events';
import { MI2 } from './backend/mi2/mi2';
import { GDBDebugSession } from './gdb';

function getLogPath() {
Expand All @@ -23,7 +22,7 @@ function getLogPath() {
}

let firstLog = true;
let doLog = false;
let doLog = true;
const logFsPath = getLogPath();

function OpenOCDLog(str: string) {
Expand Down Expand Up @@ -312,6 +311,7 @@ export class OpenOCDServerController extends EventEmitter implements GDBServerCo
this.ctiStopResume(CTIAction.init);
}
if (hasRtt) {
OpenOCDLog('RTT Monitor started');
this.startRttMonitor();
}
}
Expand Down Expand Up @@ -370,6 +370,7 @@ export class OpenOCDServerController extends EventEmitter implements GDBServerCo
private readonly tclDelimit = String.fromCharCode(0x1a);
private dbgPollCounter = 0;
private rttPollStart() {
OpenOCDLog('RTT Poll starting with interval ' + this.args.rttConfig.rtt_start_retry);
this.rttPollTimer = setInterval(async () => {
if ((this.session.miDebugger.status === 'running') && !this.rttAutoStartDetected) {
try {
Expand Down Expand Up @@ -424,6 +425,8 @@ export class OpenOCDServerController extends EventEmitter implements GDBServerCo
host: '127.0.0.1',
port: tclPortNum
};
OpenOCDLog(`Opening OpenOCD tcl socket on port ${tclPortNum}`);

this.tclSocket = net.createConnection(obj, () => {
resolve();
});
Expand Down
Loading

0 comments on commit 8b2978c

Please sign in to comment.