Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
- Updated goDebug.ts to use tabs instead of spaces.
Browse files Browse the repository at this point in the history
- Changed mode from debug_remote to remote.
- In package.son, spaces are used instead of tabs.  Cleaned my changes up to be spaces instead of tabs.
  • Loading branch information
Raul Giacoman committed Mar 21, 2016
1 parent ab5166b commit 9dcf088
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 112 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": []
Expand All @@ -143,7 +143,7 @@
},
"mode": {
"type": "string",
"description": "One of 'debug', 'debug_remote', 'test', 'exec'.",
"description": "One of 'debug', 'remote', 'test', 'exec'.",
"default": "debug"
},
"stopOnEntry": {
Expand Down
216 changes: 108 additions & 108 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,69 +144,69 @@ function log(msg?: any, ...args) {
}

class Delve {
program: string;
remotePath: string;
program: string;
remotePath: string;
debugProcess: ChildProcess;
connection: Promise<RPCConnection>;
onstdout: (str: string) => void;
onstderr: (str: string) => void;

constructor(mode: string, remotePath: string, port: number, host:string, program: string, args: string[], cwd: string, env: { [key: string]: string }, buildFlags: string, init: string) {
this.program = program;
this.remotePath = remotePath;
this.connection = new Promise((resolve, reject) => {
let serverRunning = false;
if (mode === 'debug_remote') {
this.debugProcess = null;
serverRunning = true; //assume server is running when in debug_remote mode
connectClient(port, host);
}
else
{
let dlv = getBinPath('dlv');
log('Using dlv at: ', dlv);
if (!existsSync(dlv)) {
return reject('Cannot find Delve debugger. Ensure it is in your `GOPATH/bin` or `PATH`.');
}
let dlvEnv: Object = null;
if (env) {
dlvEnv = {};
for (let k in process.env) {
dlvEnv[k] = process.env[k];
}
for (let k in env) {
dlvEnv[k] = env[k];
}
}
let dlvArgs = [mode || 'debug'];
if (mode === 'exec') {
dlvArgs = dlvArgs.concat([program]);
}
dlvArgs = dlvArgs.concat(['--headless=true', '--listen=' + host + ':' + port.toString(), '--log']);
if (buildFlags) {
dlvArgs = dlvArgs.concat(['--build-flags=' + buildFlags]);
}
if (init) {
dlvArgs = dlvArgs.concat(['--init=' + init]);
}
if (args) {
dlvArgs = dlvArgs.concat(['--', ...args]);
}

let dlvCwd = dirname(program);
try {
if (lstatSync(program).isDirectory()) {
dlvCwd = program;
}
} catch (e) { }
this.debugProcess = spawn(dlv, dlvArgs, {
cwd: dlvCwd,
env: dlvEnv,
});
}

function connectClient(port: number, host: string) {
let client = Client.$create(port, host);
this.program = program;
this.remotePath = remotePath;
this.connection = new Promise((resolve, reject) => {
let serverRunning = false;
if (mode === 'remote') {
this.debugProcess = null;
serverRunning = true; //assume server is running when in remote mode
connectClient(port, host);
}
else
{
let dlv = getBinPath('dlv');
log('Using dlv at: ', dlv);
if (!existsSync(dlv)) {
return reject('Cannot find Delve debugger. Ensure it is in your `GOPATH/bin` or `PATH`.');
}
let dlvEnv: Object = null;
if (env) {
dlvEnv = {};
for (let k in process.env) {
dlvEnv[k] = process.env[k];
}
for (let k in env) {
dlvEnv[k] = env[k];
}
}
let dlvArgs = [mode || 'debug'];
if (mode === 'exec') {
dlvArgs = dlvArgs.concat([program]);
}
dlvArgs = dlvArgs.concat(['--headless=true', '--listen=' + host + ':' + port.toString(), '--log']);
if (buildFlags) {
dlvArgs = dlvArgs.concat(['--build-flags=' + buildFlags]);
}
if (init) {
dlvArgs = dlvArgs.concat(['--init=' + init]);
}
if (args) {
dlvArgs = dlvArgs.concat(['--', ...args]);
}

let dlvCwd = dirname(program);
try {
if (lstatSync(program).isDirectory()) {
dlvCwd = program;
}
} catch (e) { }
this.debugProcess = spawn(dlv, dlvArgs, {
cwd: dlvCwd,
env: dlvEnv,
});
}

function connectClient(port: number, host: string) {
let client = Client.$create(port, host);
client.connectSocket((err, conn) => {
if (err) return reject(err);
// Add a slight delay to avoid issues on Linux with
Expand All @@ -215,28 +215,28 @@ class Delve {
resolve(conn),
200);
});
}

if (this.debugProcess != null) {
this.debugProcess.stderr.on('data', chunk => {
let str = chunk.toString();
if (this.onstderr) { this.onstderr(str); }
if (!serverRunning) {
serverRunning = true;
connectClient(port, host);
}
});
this.debugProcess.stdout.on('data', chunk => {
let str = chunk.toString();
if (this.onstdout) { this.onstdout(str); }
});
this.debugProcess.on('close', function(code) {
// TODO: Report `dlv` crash to user.
console.error('Process exiting with code: ' + code);
});
this.debugProcess.on('error', function(err) {
reject(err);
});
}

if (this.debugProcess != null) {
this.debugProcess.stderr.on('data', chunk => {
let str = chunk.toString();
if (this.onstderr) { this.onstderr(str); }
if (!serverRunning) {
serverRunning = true;
connectClient(port, host);
}
});
this.debugProcess.stdout.on('data', chunk => {
let str = chunk.toString();
if (this.onstdout) { this.onstdout(str); }
});
this.debugProcess.on('close', function(code) {
// TODO: Report `dlv` crash to user.
console.error('Process exiting with code: ' + code);
});
this.debugProcess.on('error', function(err) {
reject(err);
});
}
});
}
Expand All @@ -263,21 +263,21 @@ class Delve {
}

close() {
if (this.debugProcess === null) {
this.call<DebuggerState>('Command', [{ name: 'halt' }], (err, state) => {
if (err) {
console.error('Failed to halt.');
}
// else TODO: Can't find a way to kill remote delve.
// {
// this.call<number>('Detach', [true], (err, ret) => {
// if (err) {
// console.error('Failed to detach.');
// }
// });
// }
});
}
if (this.debugProcess === null) {
this.call<DebuggerState>('Command', [{ name: 'halt' }], (err, state) => {
if (err) {
console.error('Failed to halt.');
}
// else TODO: Can't find a way to kill remote delve.
// {
// this.call<number>('Detach', [true], (err, ret) => {
// if (err) {
// console.error('Failed to detach.');
// }
// });
// }
});
}
else this.debugProcess.kill();
}
}
Expand Down Expand Up @@ -356,26 +356,26 @@ class GoDebugSession extends DebugSession {
this.sendResponse(response);
log('ExceptionBreakPointsResponse');
}
protected toDebuggerPath(path): string {
if (this.delve.remotePath.length === 0)
return this.convertClientPathToDebugger(path);
return path.replace(this.delve.program, this.delve.remotePath);
}
protected toLocalPath(path): string {
if (this.delve.remotePath.length === 0)
return this.convertDebuggerPathToClient(path);
return path.replace(this.delve.remotePath, this.delve.program);
}

protected toDebuggerPath(path): string {
if (this.delve.remotePath.length === 0)
return this.convertClientPathToDebugger(path);
return path.replace(this.delve.program, this.delve.remotePath);
}

protected toLocalPath(path): string {
if (this.delve.remotePath.length === 0)
return this.convertDebuggerPathToClient(path);
return path.replace(this.delve.remotePath, this.delve.program);
}

protected setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): void {
log('SetBreakPointsRequest');
if (!this.breakpoints.get(args.source.path)) {
this.breakpoints.set(args.source.path, []);
}
let file = args.source.path;
let remotePath = this.toDebuggerPath(file)
let remotePath = this.toDebuggerPath(file)
let existingBPs = this.breakpoints.get(file);
Promise.all(this.breakpoints.get(file).map(existingBP => {
log('Clearing: ' + existingBP.id);
Expand Down Expand Up @@ -444,7 +444,7 @@ class GoDebugSession extends DebugSession {
location.function ? location.function.name : '<unknown>',
new Source(
basename(location.file),
this.toLocalPath(location.file)
this.toLocalPath(location.file)
//this.convertDebuggerPathToClient(location.file)
),
location.line,
Expand Down

0 comments on commit 9dcf088

Please sign in to comment.