-
Notifications
You must be signed in to change notification settings - Fork 122
Run gdb commands before connection #97 #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Gaswigue
wants to merge
4
commits into
WebFreak001:master
Choose a base branch
from
Gaswigue:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { Breakpoint, IBackend, Stack, SSHArguments, Variable } from "../backend" | ||
import { escape } from "../mi_parse" | ||
import * as ChildProcess from "child_process" | ||
import { EventEmitter } from "events" | ||
import { parseMI, MINode } from '../mi_parse'; | ||
|
@@ -10,10 +11,6 @@ import * as nativePath from "path" | |
let path = posix; | ||
var Client = require("ssh2").Client; | ||
|
||
export function escape(str: string) { | ||
return str.replace(/\\/g, "\\\\").replace(/"/g, "\\\""); | ||
} | ||
|
||
const nonOutput = /^(?:\d*|undefined)[\*\+\=]|[\~\@\&\^]/; | ||
const gdbMatch = /(?:\d*|undefined)\(gdb\)/; | ||
const numRegex = /\d+/; | ||
|
@@ -31,7 +28,7 @@ export class MI2 extends EventEmitter implements IBackend { | |
super(); | ||
} | ||
|
||
load(cwd: string, target: string, procArgs: string, separateConsole: string): Thenable<any> { | ||
load(cwd: string, target: string, autorunBeforeCmds: string[], procArgs: string, separateConsole: string): Thenable<any> { | ||
if (!nativePath.isAbsolute(target)) | ||
target = nativePath.join(cwd, target); | ||
return new Promise((resolve, reject) => { | ||
|
@@ -41,7 +38,7 @@ export class MI2 extends EventEmitter implements IBackend { | |
this.process.stdout.on("data", this.stdout.bind(this)); | ||
this.process.stderr.on("data", this.stderr.bind(this)); | ||
this.process.on("exit", (() => { this.emit("quit"); }).bind(this)); | ||
let promises = this.initCommands(target, cwd); | ||
let promises = this.initCommands(target, cwd, autorunBeforeCmds); | ||
if (procArgs && procArgs.length) | ||
promises.push(this.sendCommand("exec-arguments " + procArgs)); | ||
if (process.platform == "win32") { | ||
|
@@ -72,7 +69,7 @@ export class MI2 extends EventEmitter implements IBackend { | |
}); | ||
} | ||
|
||
ssh(args: SSHArguments, cwd: string, target: string, procArgs: string, separateConsole: string, attach: boolean): Thenable<any> { | ||
ssh(args: SSHArguments, cwd: string, target: string, autorunBeforeCmds: string[], procArgs: string, separateConsole: string, attach: boolean): Thenable<any> { | ||
return new Promise((resolve, reject) => { | ||
this.isSSH = true; | ||
this.sshReady = false; | ||
|
@@ -143,7 +140,7 @@ export class MI2 extends EventEmitter implements IBackend { | |
this.emit("quit"); | ||
this.sshConn.end(); | ||
}).bind(this)); | ||
let promises = this.initCommands(target, cwd, true, attach); | ||
let promises = this.initCommands(target, cwd, autorunBeforeCmds, true, attach); | ||
promises.push(this.sendCommand("environment-cd \"" + escape(cwd) + "\"")); | ||
if (procArgs && procArgs.length && !attach) | ||
promises.push(this.sendCommand("exec-arguments " + procArgs)); | ||
|
@@ -161,7 +158,8 @@ export class MI2 extends EventEmitter implements IBackend { | |
}); | ||
} | ||
|
||
protected initCommands(target: string, cwd: string, ssh: boolean = false, attach: boolean = false) { | ||
protected initCommands(target: string, cwd: string, autorunBeforeCmds: string[], ssh: boolean = false, attach: boolean = false) { | ||
let cmds = []; | ||
if (ssh) { | ||
if (!path.isAbsolute(target)) | ||
target = path.join(cwd, target); | ||
|
@@ -170,17 +168,17 @@ export class MI2 extends EventEmitter implements IBackend { | |
if (!nativePath.isAbsolute(target)) | ||
target = nativePath.join(cwd, target); | ||
} | ||
var cmds = [ | ||
this.sendCommand("gdb-set target-async on", true), | ||
this.sendCommand("environment-directory \"" + escape(cwd) + "\"", true) | ||
]; | ||
autorunBeforeCmds.forEach(command => { | ||
cmds.push(this.sendCommand(command)); | ||
}); | ||
if (!attach) | ||
cmds.push(this.sendCommand("file-exec-and-symbols \"" + escape(target) + "\"")); | ||
return cmds; | ||
} | ||
|
||
attach(cwd: string, executable: string, target: string): Thenable<any> { | ||
attach(cwd: string, executable: string, target: string, autorunBeforeCmds: string[]): Thenable<any> { | ||
return new Promise((resolve, reject) => { | ||
let cmds = []; | ||
let args = []; | ||
if (executable && !nativePath.isAbsolute(executable)) | ||
executable = nativePath.join(cwd, executable); | ||
|
@@ -196,39 +194,38 @@ export class MI2 extends EventEmitter implements IBackend { | |
this.process.stdout.on("data", this.stdout.bind(this)); | ||
this.process.stderr.on("data", this.stderr.bind(this)); | ||
this.process.on("exit", (() => { this.emit("quit"); }).bind(this)); | ||
var commands = [ | ||
this.sendCommand("gdb-set target-async on"), | ||
this.sendCommand("environment-directory \"" + escape(cwd) + "\"") | ||
]; | ||
autorunBeforeCmds.forEach(command => { | ||
cmds.push(this.sendCommand(command)); | ||
}); | ||
|
||
if (isExtendedRemote) { | ||
commands.push(this.sendCommand("target-select " + target)); | ||
commands.push(this.sendCommand("file-symbol-file \"" + escape(executable) + "\"")); | ||
cmds.push(this.sendCommand("file-symbol-file \"" + escape(executable) + "\"")); | ||
} | ||
Promise.all(commands).then(() => { | ||
Promise.all(cmds).then(() => { | ||
this.emit("debug-ready") | ||
resolve(); | ||
}, reject); | ||
}); | ||
} | ||
|
||
connect(cwd: string, executable: string, target: string): Thenable<any> { | ||
connect(cwd: string, executable: string, target: string, autorunBeforeCmds: string[]): Thenable<any> { | ||
return new Promise((resolve, reject) => { | ||
let commands = []; | ||
let args = []; | ||
if (executable && !nativePath.isAbsolute(executable)) | ||
executable = nativePath.join(cwd, executable); | ||
if (executable) | ||
args = args.concat([executable], this.preargs); | ||
else | ||
args = this.preargs; | ||
args = this.preargs; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is a leading whitespace here |
||
this.process = ChildProcess.spawn(this.application, args, { cwd: cwd }); | ||
this.process.stdout.on("data", this.stdout.bind(this)); | ||
this.process.stderr.on("data", this.stderr.bind(this)); | ||
this.process.on("exit", (() => { this.emit("quit"); }).bind(this)); | ||
Promise.all([ | ||
this.sendCommand("gdb-set target-async on"), | ||
this.sendCommand("environment-directory \"" + escape(cwd) + "\""), | ||
this.sendCommand("target-select remote " + target) | ||
]).then(() => { | ||
autorunBeforeCmds.forEach(command => { | ||
commands.push(this.sendCommand(command)); | ||
}); | ||
Promise.all(commands).then(() => { | ||
this.emit("debug-ready") | ||
resolve(); | ||
}, reject); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { MI2, escape } from "./mi2" | ||
import { MI2 } from "./mi2" | ||
import { escape } from "../mi_parse" | ||
import { Breakpoint } from "../backend" | ||
import * as ChildProcess from "child_process" | ||
import { posix } from "path" | ||
import * as nativePath from "path" | ||
let path = posix; | ||
|
||
export class MI2_LLDB extends MI2 { | ||
protected initCommands(target: string, cwd: string, ssh: boolean = false, attach: boolean = false) { | ||
protected initCommands(target: string, cwd: string, autorunBeforeCmds: string[], ssh: boolean = false, attach: boolean = false) { | ||
let cmds = []; | ||
if (ssh) { | ||
if (!path.isAbsolute(target)) | ||
target = path.join(cwd, target); | ||
|
@@ -15,25 +17,26 @@ export class MI2_LLDB extends MI2 { | |
if (!nativePath.isAbsolute(target)) | ||
target = nativePath.join(cwd, target); | ||
} | ||
var cmds = [ | ||
this.sendCommand("gdb-set target-async on") | ||
]; | ||
autorunBeforeCmds.forEach(command => { | ||
cmds.push(this.sendCommand(command)); | ||
}); | ||
if (!attach) | ||
cmds.push(this.sendCommand("file-exec-and-symbols \"" + escape(target) + "\"")); | ||
return cmds; | ||
} | ||
|
||
attach(cwd: string, executable: string, target: string): Thenable<any> { | ||
attach(cwd: string, executable: string, target: string, autorunBeforeCmds: string[]): Thenable<any> { | ||
return new Promise((resolve, reject) => { | ||
let cmds = []; | ||
this.process = ChildProcess.spawn(this.application, this.preargs, { cwd: cwd }); | ||
this.process.stdout.on("data", this.stdout.bind(this)); | ||
this.process.stderr.on("data", this.stderr.bind(this)); | ||
this.process.on("exit", (() => { this.emit("quit"); }).bind(this)); | ||
Promise.all([ | ||
this.sendCommand("gdb-set target-async on"), | ||
this.sendCommand("file-exec-and-symbols \"" + escape(executable) + "\""), | ||
this.sendCommand("target-attach " + target) | ||
]).then(() => { | ||
autorunBeforeCmds.forEach(command => { | ||
cmds.push(this.sendCommand(command)); | ||
}); | ||
cmds.push(this.sendCommand("file-exec-and-symbols \"" + escape(executable) + "\"")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already in the autorunBeforeCmds |
||
Promise.all(cmds).then(() => { | ||
this.emit("debug-ready"); | ||
resolve(); | ||
}, reject); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just having
$cwd
without the quotes and instead adding the quotes in the replace function would be a better idea I think because it makes the default more clean and it's more obvious to the user because there are no random quotes around it.