Skip to content

Commit 728f403

Browse files
authored
XML Translation Removal (#1056)
Remove the Launch.json to XML conversion for OpenDebugAD7. This will now pull the necessary information that OpenDebugAD7 uses and continue passing it to MICore.
1 parent 378be00 commit 728f403

File tree

8 files changed

+129
-958
lines changed

8 files changed

+129
-958
lines changed

src/MICore/JsonLaunchOptions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ public partial class LaunchOptions : BaseOptions
299299
[JsonProperty("externalConsole", DefaultValueHandling = DefaultValueHandling.Ignore)]
300300
public bool? ExternalConsole { get; set; }
301301

302+
/// <summary>
303+
/// If true, disables debuggee console redirection that is required for Integrated Terminal support.
304+
/// </summary>
305+
[JsonProperty("avoidWindowsConsoleRedirection", DefaultValueHandling = DefaultValueHandling.Ignore)]
306+
public bool? AvoidWindowsConsoleRedirection { get; set; }
307+
302308
#endregion
303309

304310
#region Constructors

src/MICore/LaunchOptions.cs

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,10 +1805,83 @@ protected void InitializeCommonOptions(Xml.LaunchOptions.BaseLaunchOptions sourc
18051805
this.Environment = new ReadOnlyCollection<EnvironmentEntry>(GetEnvironmentEntries(source.Environment));
18061806
}
18071807

1808+
private static List<string> TryAddWindowsDebuggeeConsoleRedirection(List<string> arguments)
1809+
{
1810+
if (PlatformUtilities.IsWindows()) // Only do this on Windows
1811+
{
1812+
bool stdInRedirected = false;
1813+
bool stdOutRedirected = false;
1814+
bool stdErrRedirected = false;
1815+
1816+
if (arguments != null)
1817+
{
1818+
foreach (string rawArgument in arguments)
1819+
{
1820+
string argument = rawArgument.TrimStart();
1821+
if (argument.TrimStart().StartsWith("2>", StringComparison.Ordinal))
1822+
{
1823+
stdErrRedirected = true;
1824+
}
1825+
if (argument.TrimStart().StartsWith("1>", StringComparison.Ordinal) || argument.TrimStart().StartsWith(">", StringComparison.Ordinal))
1826+
{
1827+
stdOutRedirected = true;
1828+
}
1829+
if (argument.TrimStart().StartsWith("0>", StringComparison.Ordinal) || argument.TrimStart().StartsWith("<", StringComparison.Ordinal))
1830+
{
1831+
stdInRedirected = true;
1832+
}
1833+
}
1834+
}
1835+
1836+
// If one (or more) are not redirected, then add redirection
1837+
if (!stdInRedirected || !stdOutRedirected || !stdErrRedirected)
1838+
{
1839+
int argLength = arguments.Count;
1840+
List<string> argList = new List<string>(argLength + 3);
1841+
if (arguments != null)
1842+
{
1843+
argList.AddRange(arguments);
1844+
}
1845+
1846+
if (!stdErrRedirected)
1847+
{
1848+
argList.Add("2>CON");
1849+
}
1850+
1851+
if (!stdOutRedirected)
1852+
{
1853+
argList.Add("1>CON");
1854+
}
1855+
1856+
if (!stdInRedirected)
1857+
{
1858+
argList.Add("<CON");
1859+
}
1860+
1861+
return argList;
1862+
}
1863+
}
1864+
1865+
return arguments;
1866+
}
1867+
18081868
public void InitializeLaunchOptions(Json.LaunchOptions.LaunchOptions launch)
18091869
{
18101870
this.DebuggerMIMode = ConvertMIModeString(RequireAttribute(launch.MIMode, nameof(launch.MIMode)));
1811-
this.ExeArguments = ParseArguments(launch.Args);
1871+
1872+
List<string> args = launch.Args;
1873+
1874+
if (Host.GetHostUIIdentifier() == HostUIIdentifier.VSCode &&
1875+
HostRunInTerminal.IsRunInTerminalAvailable() &&
1876+
!launch.ExternalConsole.GetValueOrDefault(false) &&
1877+
string.IsNullOrEmpty(launch.CoreDumpPath) &&
1878+
!launch.AvoidWindowsConsoleRedirection.GetValueOrDefault(false) &&
1879+
!(this is PipeLaunchOptions)) // Make sure we are not doing a PipeLaunch
1880+
{
1881+
args = TryAddWindowsDebuggeeConsoleRedirection(args);
1882+
}
1883+
1884+
this.ExeArguments = ParseArguments(args);
18121885
this.WorkingDirectory = launch.Cwd ?? String.Empty;
18131886

18141887
this.CoreDumpPath = launch.CoreDumpPath;
@@ -2046,7 +2119,8 @@ protected static string ParseArguments(IEnumerable<string> arguments, bool quote
20462119
return String.Empty;
20472120
}
20482121

2049-
private static char[] s_ARGUMENT_SEPARATORS = new char[] { ' ', '\t' };
2122+
// gdb does not like parenthesis without being quoted
2123+
private static char[] s_ARGUMENT_SEPARATORS = { ' ', '\t', '(', ')' };
20502124
protected static string QuoteArgument(string arg)
20512125
{
20522126
// If its not quoted and it has an argument separater, then quote it.

src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,9 +2226,18 @@ public bool MapCompileTimeSrcToCurrentSrc(string compilerSrc, out string current
22262226
if (hostOSCompilerSrc.StartsWith(e.CompileTimePath, comp))
22272227
{
22282228
var file = hostOSCompilerSrc.Substring(e.CompileTimePath.Length);
2229-
if (string.IsNullOrEmpty(file)) // matched the whole directory string
2229+
if (string.IsNullOrEmpty(file)) // matched the whole string
22302230
{
2231-
break; // use default
2231+
if (hostOSCompilerSrc.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) || hostOSCompilerSrc.EndsWith(Path.AltDirectorySeparatorChar.ToString(), StringComparison.Ordinal))
2232+
{
2233+
break; // directory matched, use default.
2234+
}
2235+
else
2236+
{
2237+
// Is a file
2238+
currentName = e.EditorPath; // return the matches compile time path
2239+
return true;
2240+
}
22322241
}
22332242
// must do the path break at a directory boundry, i.e. at a '\' or '/' char
22342243
char firstFilechar = file[0];

src/OpenDebugAD7/AD7DebugSession.cs

Lines changed: 35 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ internal class AD7DebugSession : DebugAdapterBase, IDebugPortNotify2, IDebugEven
5353
private int m_firstStoppingEvent;
5454
private uint m_breakCounter = 0;
5555
private bool m_isAttach;
56-
private bool m_isCoreDump;
5756
private bool m_isStopped = false;
5857
private bool m_isStepping = false;
5958

@@ -174,7 +173,7 @@ private bool ValidateProgramPath(ref string program)
174173
return true;
175174
}
176175

177-
private void SetCommonDebugSettings(Dictionary<string, JToken> args, out int sourceFileMappings)
176+
private void SetCommonDebugSettings(Dictionary<string, JToken> args)
178177
{
179178
// Save the Just My Code setting. We will set it once the engine is created.
180179
m_sessionConfig.JustMyCode = args.GetValueAsBool("justMyCode").GetValueOrDefault(m_sessionConfig.JustMyCode);
@@ -210,26 +209,26 @@ private void SetCommonDebugSettings(Dictionary<string, JToken> args, out int sou
210209
m_logger.SetLoggingConfiguration(LoggingCategory.AdapterResponse, traceResponse.Value);
211210
}
212211
}
212+
}
213+
214+
private void SetCommonMISettings(Dictionary<string, JToken> args)
215+
{
216+
string miMode = args.GetValueAsString("MIMode");
213217

214-
sourceFileMappings = 0;
215-
Dictionary<string, string> sourceFileMap = null;
218+
// If MIMode is not provided, set default to GDB.
219+
if (string.IsNullOrEmpty(miMode))
220+
{
221+
args["MIMode"] = "gdb";
222+
}
223+
else
216224
{
217-
dynamic sourceFileMapProperty = args.GetValueAsObject("sourceFileMap");
218-
if (sourceFileMapProperty != null)
225+
// If lldb and there is no miDebuggerPath, set it.
226+
bool hasMiDebuggerPath = args.ContainsKey("miDebuggerPath");
227+
if (miMode == "lldb" && !hasMiDebuggerPath)
219228
{
220-
try
221-
{
222-
sourceFileMap = sourceFileMapProperty.ToObject<Dictionary<string, string>>();
223-
sourceFileMappings = sourceFileMap.Count;
224-
}
225-
catch (Exception e)
226-
{
227-
SendMessageEvent(MessagePrefix.Error, "Configuration for 'sourceFileMap' has a format error and will be ignored.\nException: " + e.Message);
228-
sourceFileMap = null;
229-
}
229+
args["miDebuggerPath"] = MILaunchOptions.GetLLDBMIPath();
230230
}
231231
}
232-
m_pathConverter.m_pathMapper = new PathMapper(sourceFileMap);
233232
}
234233

235234
private ProtocolException VerifyLocalProcessId(string processId, string telemetryEventName, out int pid)
@@ -310,14 +309,11 @@ private static long FileTimeToPosix(FILETIME ft)
310309

311310
public void BeforeContinue()
312311
{
313-
if (!m_isCoreDump)
314-
{
315-
m_isStepping = false;
316-
m_isStopped = false;
317-
m_variableManager.Reset();
318-
m_frameHandles.Reset();
319-
m_threadFrameEnumInfos.Clear();
320-
}
312+
m_isStepping = false;
313+
m_isStopped = false;
314+
m_variableManager.Reset();
315+
m_frameHandles.Reset();
316+
m_threadFrameEnumInfos.Clear();
321317
}
322318

323319
public void Stopped(IDebugThread2 thread)
@@ -774,8 +770,7 @@ protected override void HandleLaunchRequestAsync(IRequestResponder<LaunchArgumen
774770
}
775771
}
776772

777-
int sourceFileMappings = 0;
778-
SetCommonDebugSettings(responder.Arguments.ConfigurationProperties, sourceFileMappings: out sourceFileMappings);
773+
SetCommonDebugSettings(responder.Arguments.ConfigurationProperties);
779774

780775
bool success = false;
781776
try
@@ -790,22 +785,7 @@ protected override void HandleLaunchRequestAsync(IRequestResponder<LaunchArgumen
790785
// Don't convert the workingDirectory string if we are a pipeTransport connection. We are assuming that the user has the correct directory separaters for their target OS
791786
string workingDirectoryString = pipeTransport != null ? workingDirectory : m_pathConverter.ConvertClientPathToDebugger(workingDirectory);
792787

793-
bool debugServerUsed = false;
794-
bool isOpenOCD = false;
795-
bool stopAtEntrypoint;
796-
bool visualizerFileUsed;
797-
string launchOptions = MILaunchOptions.CreateLaunchOptions(
798-
program: program,
799-
workingDirectory: workingDirectoryString,
800-
args: JsonConvert.SerializeObject(responder.Arguments.ConfigurationProperties),
801-
isPipeLaunch: responder.Arguments.ConfigurationProperties.ContainsKey("pipeTransport"),
802-
stopAtEntry: out stopAtEntrypoint,
803-
isCoreDump: out m_isCoreDump,
804-
debugServerUsed: out debugServerUsed,
805-
isOpenOCD: out isOpenOCD,
806-
visualizerFileUsed: out visualizerFileUsed);
807-
808-
m_sessionConfig.StopAtEntrypoint = stopAtEntrypoint;
788+
m_sessionConfig.StopAtEntrypoint = responder.Arguments.ConfigurationProperties.GetValueAsBool("stopAtEntry").GetValueOrDefault(false);
809789

810790
m_processId = Constants.InvalidProcessId;
811791
m_processName = program;
@@ -816,14 +796,18 @@ protected override void HandleLaunchRequestAsync(IRequestResponder<LaunchArgumen
816796
flags = enum_LAUNCH_FLAGS.LAUNCH_NODEBUG;
817797
}
818798

799+
SetCommonMISettings(responder.Arguments.ConfigurationProperties);
800+
801+
string launchJson = JsonConvert.SerializeObject(responder.Arguments.ConfigurationProperties);
802+
819803
// Then attach
820804
hr = m_engineLaunch.LaunchSuspended(null,
821805
m_port,
822806
program,
823807
null,
824808
null,
825809
null,
826-
launchOptions,
810+
launchJson,
827811
flags,
828812
0,
829813
0,
@@ -869,18 +853,11 @@ protected override void HandleLaunchRequestAsync(IRequestResponder<LaunchArgumen
869853

870854
var properties = new Dictionary<string, object>(StringComparer.Ordinal);
871855

872-
properties.Add(DebuggerTelemetry.TelemetryIsCoreDump, m_isCoreDump);
873-
if (debugServerUsed)
874-
{
875-
properties.Add(DebuggerTelemetry.TelemetryUsesDebugServer, isOpenOCD ? "openocd" : "other");
876-
}
877856
if (flags.HasFlag(enum_LAUNCH_FLAGS.LAUNCH_NODEBUG))
878857
{
879858
properties.Add(DebuggerTelemetry.TelemetryIsNoDebug, true);
880859
}
881860

882-
properties.Add(DebuggerTelemetry.TelemetryVisualizerFileUsed, visualizerFileUsed);
883-
properties.Add(DebuggerTelemetry.TelemetrySourceFileMappings, sourceFileMappings);
884861
properties.Add(DebuggerTelemetry.TelemetryMIMode, mimode);
885862

886863
DebuggerTelemetry.ReportTimedEvent(telemetryEventName, DateTime.Now - launchStartTime, properties);
@@ -930,8 +907,6 @@ protected override void HandleAttachRequestAsync(IRequestResponder<AttachArgumen
930907
JObject pipeTransport = responder.Arguments.ConfigurationProperties.GetValueAsObject("pipeTransport");
931908
bool isPipeTransport = (pipeTransport != null);
932909
bool isLocal = string.IsNullOrEmpty(miDebuggerServerAddress) && !isPipeTransport;
933-
bool visualizerFileUsed = false;
934-
int sourceFileMappings = 0;
935910
string mimode = responder.Arguments.ConfigurationProperties.GetValueAsString("MIMode");
936911

937912
if (isLocal)
@@ -968,11 +943,10 @@ protected override void HandleAttachRequestAsync(IRequestResponder<AttachArgumen
968943
return;
969944
}
970945

971-
SetCommonDebugSettings(responder.Arguments.ConfigurationProperties, sourceFileMappings: out sourceFileMappings);
946+
SetCommonDebugSettings(responder.Arguments.ConfigurationProperties);
972947

973948
string program = responder.Arguments.ConfigurationProperties.GetValueAsString("program");
974949
string executable = null;
975-
string launchOptions = null;
976950
bool success = false;
977951
try
978952
{
@@ -990,21 +964,6 @@ protected override void HandleAttachRequestAsync(IRequestResponder<AttachArgumen
990964
responder.SetError(CreateProtocolExceptionAndLogTelemetry(telemetryEventName, 1011, "debuggerPath is required for attachTransport."));
991965
return;
992966
}
993-
bool debugServerUsed = false;
994-
bool isOpenOCD = false;
995-
bool stopAtEntrypoint = false;
996-
997-
launchOptions = MILaunchOptions.CreateLaunchOptions(
998-
program: program,
999-
workingDirectory: String.Empty, // No cwd for attach
1000-
args: JsonConvert.SerializeObject(responder.Arguments.ConfigurationProperties),
1001-
isPipeLaunch: responder.Arguments.ConfigurationProperties.ContainsKey("pipeTransport"),
1002-
stopAtEntry: out stopAtEntrypoint,
1003-
isCoreDump: out m_isCoreDump,
1004-
debugServerUsed: out debugServerUsed,
1005-
isOpenOCD: out isOpenOCD,
1006-
visualizerFileUsed: out visualizerFileUsed);
1007-
1008967

1009968
if (string.IsNullOrEmpty(program))
1010969
{
@@ -1031,19 +990,6 @@ protected override void HandleAttachRequestAsync(IRequestResponder<AttachArgumen
1031990
return;
1032991
}
1033992

1034-
bool debugServerUsed = false;
1035-
bool isOpenOCD = false;
1036-
bool stopAtEntrypoint = false;
1037-
launchOptions = MILaunchOptions.CreateLaunchOptions(
1038-
program: program,
1039-
workingDirectory: string.Empty,
1040-
args: JsonConvert.SerializeObject(responder.Arguments.ConfigurationProperties),
1041-
isPipeLaunch: responder.Arguments.ConfigurationProperties.ContainsKey("pipeTransport"),
1042-
stopAtEntry: out stopAtEntrypoint,
1043-
isCoreDump: out m_isCoreDump,
1044-
debugServerUsed: out debugServerUsed,
1045-
isOpenOCD: out isOpenOCD,
1046-
visualizerFileUsed: out visualizerFileUsed);
1047993
executable = program;
1048994
m_isAttach = true;
1049995
}
@@ -1054,8 +1000,12 @@ protected override void HandleAttachRequestAsync(IRequestResponder<AttachArgumen
10541000
}
10551001
m_processName = program ?? string.Empty;
10561002

1003+
SetCommonMISettings(responder.Arguments.ConfigurationProperties);
1004+
1005+
string launchJson = JsonConvert.SerializeObject(responder.Arguments.ConfigurationProperties);
1006+
10571007
// attach
1058-
int hr = m_engineLaunch.LaunchSuspended(null, m_port, executable, null, null, null, launchOptions, 0, 0, 0, 0, this, out m_process);
1008+
int hr = m_engineLaunch.LaunchSuspended(null, m_port, executable, null, null, null, launchJson, 0, 0, 0, 0, this, out m_process);
10591009

10601010
if (hr != HRConstants.S_OK)
10611011
{
@@ -1096,8 +1046,6 @@ protected override void HandleAttachRequestAsync(IRequestResponder<AttachArgumen
10961046

10971047
var properties = new Dictionary<string, object>(StringComparer.Ordinal);
10981048
properties.Add(DebuggerTelemetry.TelemetryMIMode, mimode);
1099-
properties.Add(DebuggerTelemetry.TelemetryVisualizerFileUsed, visualizerFileUsed);
1100-
properties.Add(DebuggerTelemetry.TelemetrySourceFileMappings, sourceFileMappings);
11011049

11021050
DebuggerTelemetry.ReportTimedEvent(telemetryEventName, DateTime.Now - attachStartTime, properties);
11031051
success = true;
@@ -1252,10 +1200,7 @@ protected override void HandleStepInRequestAsync(IRequestResponder<StepInArgumen
12521200
}
12531201
catch (AD7Exception e)
12541202
{
1255-
if (m_isCoreDump)
1256-
{
1257-
responder.SetError(new ProtocolException(e.Message));
1258-
}
1203+
responder.SetError(new ProtocolException(e.Message));
12591204
}
12601205
}
12611206

0 commit comments

Comments
 (0)