From 174a35be76eb64526f1d50d0826f14aaa871cf43 Mon Sep 17 00:00:00 2001 From: MrStanislav0 Date: Sat, 24 Aug 2024 12:41:28 +0300 Subject: [PATCH 1/2] Fix show a list local processes, if remote connection failed (useExtendedRemote) --- Extension/src/Debugger/attachToProcess.ts | 7 ++++++- Extension/src/SSH/sshCommandRunner.ts | 2 +- Extension/src/common.ts | 5 +++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Extension/src/Debugger/attachToProcess.ts b/Extension/src/Debugger/attachToProcess.ts index 5fddbfc16b..4ff3ce0c2e 100644 --- a/Extension/src/Debugger/attachToProcess.ts +++ b/Extension/src/Debugger/attachToProcess.ts @@ -187,13 +187,18 @@ export class RemoteAttachPicker { const args: string[] = [`-ex "target extended-remote ${miDebuggerServerAddress}"`, '-ex "info os processes"', '-batch']; let processListOutput: util.ProcessReturnType = await util.spawnChildProcess(miDebuggerPath, args); // The device may not be responsive for a while during the restart after image deploy. Retry 5 times. - for (let i: number = 0; i < 5 && !processListOutput.succeeded; i++) { + for (let i: number = 0; i < 5 && !processListOutput.succeeded && processListOutput.outputError.length === 0; i++) { processListOutput = await util.spawnChildProcess(miDebuggerPath, args); } if (!processListOutput.succeeded) { throw new Error(localize('failed.to.make.gdb.connection', 'Failed to make GDB connection: "{0}".', processListOutput.output)); } + + if (processListOutput.outputError.length !== 0) { + throw new Error(localize('failed.to.make.gdb.connection', 'Failed to make GDB connection: "{0}".', processListOutput.outputError)); + } + const processes: AttachItem[] = this.parseProcessesFromInfoOsProcesses(processListOutput.output); if (!processes || processes.length === 0) { throw new Error(localize('failed.to.parse.processes', 'Failed to parse processes: "{0}".', processListOutput.output)); diff --git a/Extension/src/SSH/sshCommandRunner.ts b/Extension/src/SSH/sshCommandRunner.ts index b9df7f7b80..be60f83db3 100644 --- a/Extension/src/SSH/sshCommandRunner.ts +++ b/Extension/src/SSH/sshCommandRunner.ts @@ -304,7 +304,7 @@ export function runInteractiveSshTerminalCommand(args: ITerminalCommandArgs): Pr // When using showLoginTerminal, stdout include the passphrase prompt, etc. Try to get just the command output on the last line. const actualOutput: string | undefined = cancel ? '' : lastNonemptyLine(stdout); - result.resolve({ succeeded: !exitCode, exitCode, output: actualOutput || '' }); + result.resolve({ succeeded: !exitCode, exitCode, outputError: '', output: actualOutput || '' }); }; const failed = (error?: any) => { diff --git a/Extension/src/common.ts b/Extension/src/common.ts index 9bddeba2c0..82c93eba04 100644 --- a/Extension/src/common.ts +++ b/Extension/src/common.ts @@ -753,6 +753,7 @@ export interface ProcessReturnType { succeeded: boolean; exitCode?: number | NodeJS.Signals; output: string; + outputError : string; } export async function spawnChildProcess(program: string, args: string[] = [], continueOn?: string, skipLogging?: boolean, cancellationToken?: vscode.CancellationToken): Promise { @@ -766,7 +767,7 @@ export async function spawnChildProcess(program: string, args: string[] = [], co const programOutput: ProcessOutput = await spawnChildProcessImpl(program, args, continueOn, skipLogging, cancellationToken); const exitCode: number | NodeJS.Signals | undefined = programOutput.exitCode; if (programOutput.exitCode) { - return { succeeded: false, exitCode, output: programOutput.stderr || programOutput.stdout || localize('process.exited', 'Process exited with code {0}', exitCode) }; + return { succeeded: false, exitCode, outputError: programOutput.stderr, output: programOutput.stderr || programOutput.stdout || localize('process.exited', 'Process exited with code {0}', exitCode) }; } else { let stdout: string; if (programOutput.stdout.length) { @@ -775,7 +776,7 @@ export async function spawnChildProcess(program: string, args: string[] = [], co } else { stdout = localize('process.succeeded', 'Process executed successfully.'); } - return { succeeded: true, exitCode, output: stdout }; + return { succeeded: true, exitCode, outputError: programOutput.stderr, output: stdout }; } } From 3bb812bd0fd5094c3a175a0928bd1b601230531f Mon Sep 17 00:00:00 2001 From: MrStanislav0 Date: Mon, 26 Aug 2024 16:02:30 +0300 Subject: [PATCH 2/2] Fix error linter --- Extension/src/common.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Extension/src/common.ts b/Extension/src/common.ts index 82c93eba04..c962a719cd 100644 --- a/Extension/src/common.ts +++ b/Extension/src/common.ts @@ -753,7 +753,7 @@ export interface ProcessReturnType { succeeded: boolean; exitCode?: number | NodeJS.Signals; output: string; - outputError : string; + outputError: string; } export async function spawnChildProcess(program: string, args: string[] = [], continueOn?: string, skipLogging?: boolean, cancellationToken?: vscode.CancellationToken): Promise {