Skip to content

Commit 1e5e292

Browse files
author
gc46
authored
Merge pull request #1385 from microsoft/revert-1384-main
Revert "Merge main into 'release-cpptools' for v1.15.0"
2 parents 7ae9e4a + 8e7e3bd commit 1e5e292

15 files changed

Lines changed: 103 additions & 305 deletions

File tree

src/AndroidDebugLauncher/Launcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ private LaunchOptions SetupForDebuggingWorker(CancellationToken token)
459459

460460
launchOptions.DebuggerMIMode = MIMode.Gdb;
461461

462-
launchOptions.VisualizerFiles.Add("Microsoft.Android.natvis");
462+
launchOptions.VisualizerFile = "Microsoft.Android.natvis";
463463
launchOptions.WaitDynamicLibLoad = _launchOptions.WaitDynamicLibLoad;
464464

465465
return launchOptions;

src/DebugEngineHost/HostNatvisProject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static IDisposable WatchNatvisOptionSetting(HostConfigurationStore config
104104
IDisposable disposable = rmw.CurrentMonitor;
105105

106106
// Watch NatvisDiagnostic section
107-
rmw = new RegisterMonitorWrapper(CreateAndStartNatvisDiagnosticMonitor(checkForSection, natvisLogger));
107+
rmw = new RegisterMonitorWrapper(CreateAndStartNatvisDiagnosticMonitor(natvisDiagnosticSection, natvisLogger));
108108

109109
disposable.Dispose();
110110
}

src/DebugEngineHost/RegistryMonitor.cs

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,14 @@ private static extern int RegNotifyChangeKeyValue(SafeRegistryHandle hKey, bool
4747

4848
#endregion
4949

50-
private readonly HostConfigurationSection _section;
50+
private HostConfigurationSection _section;
5151
private readonly bool _watchSubtree;
5252

53-
// Set when monitoring is stopped
54-
private AutoResetEvent _stoppedEvent;
53+
// Set when registry value is changed
54+
private AutoResetEvent m_changeEvent;
5555

56-
// Members to handle multiple stop calls.
57-
private bool _isStopped = false;
58-
private readonly object _stopLock = new object();
56+
// Set when monitoring is stopped
57+
private AutoResetEvent m_stoppedEvent;
5958

6059
/// <summary>
6160
/// Occurs when the specified registry key has changed.
@@ -81,13 +80,9 @@ public void Start()
8180

8281
public void Stop()
8382
{
84-
lock (_stopLock)
83+
if (m_stoppedEvent != null)
8584
{
86-
if (!_isStopped)
87-
{
88-
_stoppedEvent?.Set();
89-
_isStopped = true;
90-
}
85+
m_stoppedEvent.Set();
9186
}
9287
}
9388

@@ -98,52 +93,53 @@ private void Monitor()
9893
bool stopped = false;
9994
try
10095
{
101-
_stoppedEvent = new AutoResetEvent(false);
102-
using (AutoResetEvent registryChangedEvent = new AutoResetEvent(false))
103-
{
104-
IntPtr handle = registryChangedEvent.SafeWaitHandle.DangerousGetHandle();
96+
m_stoppedEvent = new AutoResetEvent(false);
97+
m_changeEvent = new AutoResetEvent(false);
10598

106-
int errorCode = RegNotifyChangeKeyValue(_section.Handle, _watchSubtree, RegChangeNotifyFilter.REG_NOTIFY_CHANGE_NAME | RegChangeNotifyFilter.REG_NOTIFY_CHANGE_LAST_SET, handle, true);
107-
if (errorCode != 0) // 0 is ERROR_SUCCESS
108-
{
109-
_nativsLogger?.WriteLine(LogLevel.Error, Resource.Error_WatchRegistry, errorCode);
110-
}
111-
else
99+
IntPtr handle = m_changeEvent.SafeWaitHandle.DangerousGetHandle();
100+
101+
int errorCode = RegNotifyChangeKeyValue(_section.Handle, _watchSubtree, RegChangeNotifyFilter.REG_NOTIFY_CHANGE_NAME | RegChangeNotifyFilter.REG_NOTIFY_CHANGE_LAST_SET, handle, true);
102+
if (errorCode != 0) // 0 is ERROR_SUCCESS
103+
{
104+
_nativsLogger?.WriteLine(LogLevel.Error, Resource.Error_WatchRegistry, errorCode);
105+
}
106+
else
107+
{
108+
while (!stopped)
112109
{
113-
while (!stopped)
114-
{
115-
int waitResult = WaitHandle.WaitAny(new WaitHandle[] { _stoppedEvent, registryChangedEvent });
110+
int waitResult = WaitHandle.WaitAny(new WaitHandle[] { m_stoppedEvent, m_changeEvent });
116111

117-
if (waitResult == 0)
118-
{
119-
stopped = true;
120-
}
121-
else
112+
if (waitResult == 0)
113+
{
114+
stopped = true;
115+
}
116+
else
117+
{
118+
errorCode = RegNotifyChangeKeyValue(_section.Handle, _watchSubtree, RegChangeNotifyFilter.REG_NOTIFY_CHANGE_NAME | RegChangeNotifyFilter.REG_NOTIFY_CHANGE_LAST_SET, handle, true);
119+
if (errorCode != 0) // 0 is ERROR_SUCCESS
122120
{
123-
errorCode = RegNotifyChangeKeyValue(_section.Handle, _watchSubtree, RegChangeNotifyFilter.REG_NOTIFY_CHANGE_NAME | RegChangeNotifyFilter.REG_NOTIFY_CHANGE_LAST_SET, handle, true);
124-
if (errorCode != 0) // 0 is ERROR_SUCCESS
125-
{
126-
_nativsLogger?.WriteLine(LogLevel.Error, Resource.Error_WatchRegistry, errorCode);
127-
break;
128-
}
129-
RegChanged?.Invoke(this, null);
121+
_nativsLogger?.WriteLine(LogLevel.Error, Resource.Error_WatchRegistry, errorCode);
122+
break;
130123
}
124+
RegChanged?.Invoke(this, null);
131125
}
132126
}
133127
}
134128
}
135129
finally
136130
{
137-
_stoppedEvent.Dispose();
138-
_stoppedEvent = null;
139-
140131
_section.Dispose();
132+
m_stoppedEvent?.Dispose();
133+
m_changeEvent?.Dispose();
134+
135+
m_stoppedEvent = null;
136+
m_changeEvent = null;
141137
}
142138
}
143139

144140
public void Dispose()
145141
{
146-
Stop(); // Stopping the monitor will dispose of the AutoResetEvent and HostConfigurationSection
142+
m_stoppedEvent?.Dispose();
147143
}
148144
}
149145
}

src/MICore/JsonLaunchOptions.cs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ public abstract partial class BaseOptions
3939
public string TargetArchitecture { get; set; }
4040

4141
/// <summary>
42-
/// .natvis files to be used when debugging this process. This option is not compatible with GDB pretty printing. Please also see "showDisplayString" if using this setting.
42+
/// .natvis file to be used when debugging this process. This option is not compatible with GDB pretty printing. Please also see "showDisplayString" if using this setting.
4343
/// </summary>
4444
[JsonProperty("visualizerFile", DefaultValueHandling = DefaultValueHandling.Ignore)]
45-
[JsonConverter(typeof(VisualizerFileConverter))]
46-
public List<string> VisualizerFile { get; set; }
45+
public string VisualizerFile { get; set; }
4746

4847
/// <summary>
4948
/// When a visualizerFile is specified, showDisplayString will enable the display string. Turning this option on can cause slower performance during debugging.
@@ -124,37 +123,6 @@ public abstract partial class BaseOptions
124123
public UnknownBreakpointHandling? UnknownBreakpointHandling { get; set; }
125124
}
126125

127-
internal class VisualizerFileConverter : JsonConverter
128-
{
129-
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
130-
{
131-
List<string> visualizerFile = new List<string>();
132-
if (reader.TokenType == JsonToken.StartArray)
133-
{
134-
visualizerFile = serializer.Deserialize<List<string>>(reader);
135-
}
136-
else if (reader.TokenType == JsonToken.String)
137-
{
138-
visualizerFile.Add(reader.Value.ToString());
139-
}
140-
else
141-
{
142-
throw new JsonReaderException(MICoreResources.Error_IncorrectVisualizerFileFormat);
143-
}
144-
return visualizerFile;
145-
}
146-
147-
public override bool CanConvert(Type objectType)
148-
{
149-
throw new NotImplementedException();
150-
}
151-
152-
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
153-
{
154-
throw new NotImplementedException();
155-
}
156-
}
157-
158126
public partial class AttachOptions : BaseOptions
159127
{
160128
#region Public Properties for Serialization
@@ -176,7 +144,7 @@ public AttachOptions(
176144
int processId,
177145
string type = null,
178146
string targetArchitecture = null,
179-
List<string> visualizerFile = null,
147+
string visualizerFile = null,
180148
bool? showDisplayString = null,
181149
string additionalSOLibSearchPath = null,
182150
string MIMode = null,
@@ -440,7 +408,7 @@ public LaunchOptions(
440408
List<SetupCommand> postRemoteConnectCommands = null,
441409
List<SetupCommand> customLaunchSetupCommands = null,
442410
LaunchCompleteCommand? launchCompleteCommand = null,
443-
List<string> visualizerFile = null,
411+
string visualizerFile = null,
444412
bool? showDisplayString = null,
445413
List<Environment> environment = null,
446414
string additionalSOLibSearchPath = null,

src/MICore/LaunchOptions.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -960,10 +960,19 @@ public string AdditionalSOLibSearchPath
960960
}
961961
}
962962

963+
private string _visualizerFile;
963964
/// <summary>
964-
/// Collection of natvis files to use when evaluating
965+
/// [Optional] Natvis file name - from install location
965966
/// </summary>
966-
public List<string> VisualizerFiles { get; } = new List<string>();
967+
public string VisualizerFile
968+
{
969+
get { return _visualizerFile; }
970+
set
971+
{
972+
VerifyCanModifyProperty(nameof(VisualizerFile));
973+
_visualizerFile = value;
974+
}
975+
}
967976

968977
private bool _waitDynamicLibLoad = true;
969978
/// <summary>
@@ -1570,9 +1579,9 @@ private void Merge(AttachOptionsForConnection suppOptions)
15701579
{
15711580
DebugChildProcesses = suppOptions.DebugChildProcesses;
15721581
}
1573-
if (!this.VisualizerFiles.Contains(suppOptions.VisualizerFile))
1582+
if (string.IsNullOrWhiteSpace(VisualizerFile))
15741583
{
1575-
this.VisualizerFiles.Add(suppOptions.VisualizerFile);
1584+
VisualizerFile = suppOptions.VisualizerFile;
15761585
}
15771586
if (suppOptions.ShowDisplayStringSpecified)
15781587
{
@@ -1762,10 +1771,7 @@ protected void InitializeCommonOptions(Json.LaunchOptions.BaseOptions options)
17621771
this.TargetArchitecture = ConvertTargetArchitectureAttribute(options.TargetArchitecture);
17631772
}
17641773

1765-
if (options.VisualizerFile != null && options.VisualizerFile.Count > 0)
1766-
{
1767-
this.VisualizerFiles.AddRange(options.VisualizerFile);
1768-
}
1774+
this.VisualizerFile = options.VisualizerFile;
17691775
this.ShowDisplayString = options.ShowDisplayString.GetValueOrDefault(false);
17701776

17711777
this.AdditionalSOLibSearchPath = String.IsNullOrEmpty(this.AdditionalSOLibSearchPath) ?
@@ -1835,8 +1841,8 @@ protected void InitializeCommonOptions(Xml.LaunchOptions.BaseLaunchOptions sourc
18351841
if (string.IsNullOrEmpty(this.WorkingDirectory))
18361842
this.WorkingDirectory = source.WorkingDirectory;
18371843

1838-
if (!string.IsNullOrEmpty(source.VisualizerFile))
1839-
this.VisualizerFiles.Add(source.VisualizerFile);
1844+
if (string.IsNullOrEmpty(this.VisualizerFile))
1845+
this.VisualizerFile = source.VisualizerFile;
18401846

18411847
this.ShowDisplayString = source.ShowDisplayString;
18421848
this.WaitDynamicLibLoad = source.WaitDynamicLibLoad;

src/MICore/MICoreResources.Designer.cs

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MICore/MICoreResources.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,4 @@ Error: {1}</value>
326326
<data name="Error_SourceFileMapInvalidEditorPath" xml:space="preserve">
327327
<value>'editorPath' can not be null or empty</value>
328328
</data>
329-
<data name="Error_IncorrectVisualizerFileFormat" xml:space="preserve">
330-
<value>'visualizerFile' must be a string or array of strings.</value>
331-
</data>
332329
</root>

src/MICoreUnitTests/BasicLaunchOptionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ internal void VerifyCoreApisPresent()
263263
launchOptions.WorkingDirectory = "/home/user";
264264
launchOptions.DebuggerMIMode = MIMode.Gdb;
265265
launchOptions.WaitDynamicLibLoad = false;
266-
launchOptions.VisualizerFiles.Add(@"c:\myproject\file.natvis");
266+
launchOptions.VisualizerFile = @"c:\myproject\file.natvis";
267267
launchOptions.SourceMap = new ReadOnlyCollection<SourceMapEntry>(new List<SourceMapEntry>());
268268
launchOptions.Environment = new ReadOnlyCollection<EnvironmentEntry>(new List<EnvironmentEntry>());
269269
Microsoft.DebugEngineHost.HostConfigurationStore configStore = null;

src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ private async Task EnsureModulesLoaded()
543543
public async Task Initialize(HostWaitLoop waitLoop, CancellationToken token)
544544
{
545545
bool success = false;
546-
Natvis.Initialize(_launchOptions.VisualizerFiles);
546+
Natvis.Initialize(_launchOptions.VisualizerFile);
547547
int total = 1;
548548

549549
await this.WaitForConsoleDebuggerInitialize(token);

0 commit comments

Comments
 (0)