Skip to content

Commit

Permalink
Use MONO_ENV_OPTIONS to pass the debug arguments to mono (#66)
Browse files Browse the repository at this point in the history
This allows passing the arguments to e.g. a mono built from the dotnet/runtime repo since the executable doesn't take the usual mono options.

Example of launch.json:

```
{
            "type": "mono",
            "request": "launch",
            "name": "mono-netcore",
            "program": "/Users/thaysgrazia/runtime/artifacts/bin/MyConsoleApp/Debug/net5.0/MyConsoleApp.dll",
            "runtimeExecutable": "/Users/thaysgrazia/runtime/.dotnet-mono/dotnet"
}
```

Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
  • Loading branch information
thaystg and akoeplinger committed Aug 20, 2020
1 parent 13c64be commit 0f7bfa8
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/MonoDebugSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,12 @@ public override async void Launch(Response response, dynamic args)


// validate argument 'env'
Dictionary<string, string> env = null;
Dictionary<string, string> env = new Dictionary<string, string>();
var environmentVariables = args.env;
if (environmentVariables != null) {
env = new Dictionary<string, string>();
foreach (var entry in environmentVariables) {
env.Add((string)entry.Name, (string)entry.Value);
}
if (env.Count == 0) {
env = null;
}
}

const string host = "127.0.0.1";
Expand All @@ -260,11 +256,18 @@ public override async void Launch(Response response, dynamic args)
var cmdLine = new List<String>();

bool debug = !getBool(args, "noDebug", false);

if (debug) {
cmdLine.Add("--debug");
cmdLine.Add(String.Format("--debugger-agent=transport=dt_socket,server=y,address={0}:{1}", host, port));
if (!env.ContainsKey("MONO_ENV_OPTIONS"))
env["MONO_ENV_OPTIONS"] = $" --debug --debugger-agent=transport=dt_socket,server=y,address={host}:{port}";
else
env["MONO_ENV_OPTIONS"] = $" --debug --debugger-agent=transport=dt_socket,server=y,address={host}:{port} " + env["MONO_ENV_OPTIONS"];
}


if (env.Count == 0) {
env = null;
}

// add 'runtimeArgs'
if (args.runtimeArgs != null) {
string[] runtimeArguments = args.runtimeArgs.ToObject<string[]>();
Expand Down Expand Up @@ -305,13 +308,12 @@ public override async void Launch(Response response, dynamic args)
if (console == "externalTerminal" || console == "integratedTerminal") {

cmdLine.Insert(0, mono_path);

var termArgs = new {
kind = console == "integratedTerminal" ? "integrated" : "external",
title = "Node Debug Console",
cwd = workingDirectory,
args = cmdLine.ToArray(),
env = environmentVariables
env
};

var resp = await SendRequest("runInTerminal", termArgs);
Expand Down

0 comments on commit 0f7bfa8

Please sign in to comment.