Skip to content

Commit 90d24ce

Browse files
authored
Merge pull request #338 from brownts/bugfix/ssh_lldb_extraargs
Fix extra debugger args for LLDB and SSH.
2 parents 5114701 + 12cd8e5 commit 90d24ce

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* fix additional race conditions with setting breakpoints #313 (@brownts)
1919
* fix stack frame expansion in editor via use of the `startFrame` parameter #312 (@brownts)
2020
* allow specification of port/x11port via variable (as numeric string) #265 (@GitMensch)
21+
* Extra debugger arguments now work in all configurations #316, #338 fixing #206 (@GitMensch, @brownts)
2122

2223
# 0.25.1
2324

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,52 @@ Because some builds requires one or more environment files to be sourced before
151151
command, you can use the `ssh.bootstrap` option to add some extra commands which will be prepended
152152
to the debugger call (using `&&` to join both).
153153

154+
### Extra Debugger Arguments
155+
156+
Additional arguments can be supplied to the debugger if needed. These will be added when
157+
the debugger executable (e.g., gdb, lldb-mi, etc.) is launched. Extra debugger arguments
158+
are supplied via the `debugger_args` setting. Note that the behavior of escaping these
159+
options depends on the environment in which the debugger is started. For non-SSH
160+
debugging, the options are passed directly to the application and therefore no escaping is
161+
necessary (other than what is necessary for the JSON configuration). However, as a result
162+
of the options being passed directly to the application, care must be taken to place
163+
switches and switch values as separate entities in `debugger_args`, if they would normally
164+
be separated by a space. For example, supplying the option and value
165+
`-iex "set $foo = \"bar\""` would consist of the following `debugger_args`:
166+
```json
167+
"debugger_args" : ["-iex", "set $foo = \"bar\""]
168+
```
169+
If `=` is used to associate switches with their values, than the switch and value should
170+
be placed together instead. In fact, the following example shows 4 different ways in
171+
which to specify the same switch and value, using both short and long format, as well as
172+
switch values supplied as a separate parameter or supplied via the `=`:
173+
- ```json
174+
"debugger_args" : ["-iex", "set $foo = \"bar\""]
175+
```
176+
- ```json
177+
"debugger_args" : ["-iex=set $foo = \"bar\""]
178+
```
179+
- ```json
180+
"debugger_args" : ["--init-eval-command", "set $foo = \"bar\""]
181+
```
182+
- ```json
183+
"debugger_args" : ["--init-eval-command=set $foo = \"bar\""]
184+
```
185+
Where escaping is really necessary is when running the debugger over SSH. In this case,
186+
the options are not passed directly to the application, but are instead combined with the
187+
application name, joined together with any other options, and sent to the remote system to
188+
be parsed and executed. Thus, depending on the remote system, different escaping may be
189+
necessary. The following shows how the same command as above needs to be escaped
190+
differently based on whether the remote system is a POSIX or a Windows system.
191+
- SSH to Linux machine:
192+
```json
193+
"debugger_args": ["-iex", "'set $foo = \"bar\"'"]
194+
```
195+
- SSH to Windows machine:
196+
```json
197+
"debugger_args": ["-iex", "\"set $foo = \\\"bar\\\"\""]
198+
```
199+
You may need to experiment to find the correct escaping necessary for the command to be
200+
sent to the debugger as you intended.
201+
154202
## [Issues](https://github.com/WebFreak001/code-debug)

src/backend/mi2/mi2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export class MI2 extends EventEmitter implements IBackend {
141141
screen: args.remotex11screen
142142
};
143143
}
144-
let sshCMD = this.application + " " + this.preargs.join(" ");
144+
let sshCMD = this.application + " " + this.preargs.concat(this.extraargs || []).join(" ");
145145
if (args.bootstrap) sshCMD = args.bootstrap + " && " + sshCMD;
146146
if (attach)
147147
sshCMD += " -p " + target;

src/backend/mi2/mi2lldb.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export class MI2_LLDB extends MI2 {
3737

3838
attach(cwd: string, executable: string, target: string): Thenable<any> {
3939
return new Promise((resolve, reject) => {
40-
this.process = ChildProcess.spawn(this.application, this.preargs, { cwd: cwd, env: this.procEnv });
40+
const args = this.preargs.concat(this.extraargs || []);
41+
this.process = ChildProcess.spawn(this.application, args, { cwd: cwd, env: this.procEnv });
4142
this.process.stdout.on("data", this.stdout.bind(this));
4243
this.process.stderr.on("data", this.stderr.bind(this));
4344
this.process.on("exit", (() => { this.emit("quit"); }).bind(this));

0 commit comments

Comments
 (0)