Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
194 lines (160 loc) · 8.32 KB

File metadata and controls

194 lines (160 loc) · 8.32 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import { PsProcessParser } from './nativeAttach';
import { AttachItem, showQuickPick } from './attachQuickPick';
import { CppSettings } from '../LanguageServer/settings';
import * as debugUtils from './utils';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as util from '../common';
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
export interface AttachItemsProvider {
getAttachItems(): Promise<AttachItem[]>;
}
export class AttachPicker {
constructor(private attachItemsProvider: AttachItemsProvider) { }
public ShowAttachEntries(): Promise<string | undefined> {
return util.isExtensionReady().then(ready => {
if (!ready) {
util.displayExtensionNotReadyPrompt();
} else {
return showQuickPick(() => this.attachItemsProvider.getAttachItems());
}
});
}
}
export class RemoteAttachPicker {
constructor() {
this._channel = vscode.window.createOutputChannel('remote-attach');
}
private _channel: vscode.OutputChannel;
public ShowAttachEntries(config: any): Promise<string | undefined> {
return util.isExtensionReady().then(ready => {
if (!ready) {
util.displayExtensionNotReadyPrompt();
} else {
this._channel.clear();
let pipeTransport: any = config ? config.pipeTransport : undefined;
if (!pipeTransport) {
return Promise.reject<string>(new Error(localize("no.pipetransport", "Chosen debug configuration does not contain {0}", "pipeTransport")));
}
let pipeProgram: string | undefined;
if (os.platform() === 'win32' &&
pipeTransport.pipeProgram &&
!fs.existsSync(pipeTransport.pipeProgram)) {
const pipeProgramStr: string = pipeTransport.pipeProgram.toLowerCase().trim();
const expectedArch: debugUtils.ArchType = debugUtils.ArchType[process.arch as keyof typeof debugUtils.ArchType];
// Check for pipeProgram
if (!fs.existsSync(config.pipeTransport.pipeProgram)) {
pipeProgram = debugUtils.ArchitectureReplacer.checkAndReplaceWSLPipeProgram(pipeProgramStr, expectedArch);
}
// If pipeProgram does not get replaced and there is a pipeCwd, concatenate with pipeProgramStr and attempt to replace.
if (!pipeProgram && config.pipeTransport.pipeCwd) {
const pipeCwdStr: string = config.pipeTransport.pipeCwd.toLowerCase().trim();
const newPipeProgramStr: string = path.join(pipeCwdStr, pipeProgramStr);
if (!fs.existsSync(newPipeProgramStr)) {
pipeProgram = debugUtils.ArchitectureReplacer.checkAndReplaceWSLPipeProgram(newPipeProgramStr, expectedArch);
}
}
}
if (!pipeProgram) {
pipeProgram = pipeTransport.pipeProgram;
}
let pipeArgs: string[] = pipeTransport.pipeArgs;
let argList: string = RemoteAttachPicker.createArgumentList(pipeArgs);
let pipeCmd: string = `"${pipeProgram}" ${argList}`;
return this.getRemoteOSAndProcesses(pipeCmd)
.then(processes => {
let attachPickOptions: vscode.QuickPickOptions = {
matchOnDetail: true,
matchOnDescription: true,
placeHolder: localize("select.process.attach", "Select the process to attach to")
};
return vscode.window.showQuickPick(processes, attachPickOptions)
.then(item => item ? item.id : Promise.reject<string>(new Error(localize("process.not.selected", "Process not selected."))));
});
}
});
}
// Creates a string to run on the host machine which will execute a shell script on the remote machine to retrieve OS and processes
private getRemoteProcessCommand(): string {
let innerQuote: string = `'`;
let outerQuote: string = `"`;
let parameterBegin: string = `$(`;
let parameterEnd: string = `)`;
let escapedQuote: string = `\\\"`;
let settings: CppSettings = new CppSettings();
if (settings.useBacktickCommandSubstitution) {
parameterBegin = `\``;
parameterEnd = `\``;
escapedQuote = `\"`;
}
// Must use single quotes around the whole command and double quotes for the argument to `sh -c` because Linux evaluates $() inside of double quotes.
// Having double quotes for the outerQuote will have $(uname) replaced before it is sent to the remote machine.
if (os.platform() !== "win32") {
innerQuote = `"`;
outerQuote = `'`;
}
return `${outerQuote}sh -c ${innerQuote}uname && if [ ${parameterBegin}uname${parameterEnd} = ${escapedQuote}Linux${escapedQuote} ] ; ` +
`then ${PsProcessParser.psLinuxCommand} ; elif [ ${parameterBegin}uname${parameterEnd} = ${escapedQuote}Darwin${escapedQuote} ] ; ` +
`then ${PsProcessParser.psDarwinCommand}; fi${innerQuote}${outerQuote}`;
}
private getRemoteOSAndProcesses(pipeCmd: string): Promise<AttachItem[]> {
// Do not add any quoting in execCommand.
const execCommand: string = `${pipeCmd} ${this.getRemoteProcessCommand()}`;
return util.execChildProcess(execCommand, undefined, this._channel).then(output => {
// OS will be on first line
// Processes will follow if listed
let lines: string[] = output.split(/\r?\n/);
if (lines.length === 0) {
return Promise.reject<AttachItem[]>(new Error(localize("pipe.failed", "Pipe transport failed to get OS and processes.")));
} else {
let remoteOS: string = lines[0].replace(/[\r\n]+/g, '');
if (remoteOS !== "Linux" && remoteOS !== "Darwin") {
return Promise.reject<AttachItem[]>(new Error(`Operating system "${remoteOS}" not supported.`));
}
// Only got OS from uname
if (lines.length === 1) {
return Promise.reject<AttachItem[]>(new Error(localize("no.process.list", "Transport attach could not obtain processes list.")));
} else {
let processes: string[] = lines.slice(1);
return PsProcessParser.ParseProcessFromPsArray(processes)
.sort((a, b) => {
if (a.name === undefined) {
if (b.name === undefined) {
return 0;
}
return 1;
}
if (b.name === undefined) {
return -1;
}
let aLower: string = a.name.toLowerCase();
let bLower: string = b.name.toLowerCase();
if (aLower === bLower) {
return 0;
}
return aLower < bLower ? -1 : 1;
})
.map(p => p.toAttachItem());
}
}
});
}
private static createArgumentList(args: string[]): string {
let argsString: string = "";
for (let arg of args) {
if (argsString) {
argsString += " ";
}
argsString += `"${arg}"`;
}
return argsString;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.