Skip to content

Commit

Permalink
Fix show a list local processes, if remote connection failed (useExte…
Browse files Browse the repository at this point in the history
…ndedRemote)
  • Loading branch information
MrStanislav0 committed Aug 24, 2024
1 parent d3cd4fc commit 174a35b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion Extension/src/Debugger/attachToProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion Extension/src/SSH/sshCommandRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
5 changes: 3 additions & 2 deletions Extension/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ export interface ProcessReturnType {
succeeded: boolean;
exitCode?: number | NodeJS.Signals;
output: string;
outputError : string;

Check failure on line 756 in Extension/src/common.ts

View workflow job for this annotation

GitHub Actions / job / build

Unexpected space before the ':'

Check failure on line 756 in Extension/src/common.ts

View workflow job for this annotation

GitHub Actions / job / build

Unexpected space before the ':'

Check failure on line 756 in Extension/src/common.ts

View workflow job for this annotation

GitHub Actions / job / build

Unexpected space before the ':'
}

export async function spawnChildProcess(program: string, args: string[] = [], continueOn?: string, skipLogging?: boolean, cancellationToken?: vscode.CancellationToken): Promise<ProcessReturnType> {
Expand All @@ -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) {
Expand All @@ -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 };
}
}

Expand Down

0 comments on commit 174a35b

Please sign in to comment.