Skip to content
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

Fix nested calls to Assembly Load Start tracing #55700

Merged
merged 4 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/coreclr/binder/bindertracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ bool BinderTracing::IsEnabled()

namespace BinderTracing
{
static thread_local bool t_AssemblyLoadStartInProgress = false;

AssemblyBindOperation::AssemblyBindOperation(AssemblySpec *assemblySpec, const WCHAR *assemblyPath)
: m_bindRequest { assemblySpec, nullptr, assemblyPath }
, m_populatedBindRequest { false }
Expand All @@ -209,6 +211,7 @@ namespace BinderTracing
if (!BinderTracing::IsEnabled() || ShouldIgnoreBind())
return;

t_AssemblyLoadStartInProgress = true;
PopulateBindRequest(m_bindRequest);
m_populatedBindRequest = true;
FireAssemblyLoadStart(m_bindRequest);
Expand All @@ -218,6 +221,8 @@ namespace BinderTracing
{
if (BinderTracing::IsEnabled() && !ShouldIgnoreBind())
{
t_AssemblyLoadStartInProgress = false;

// Make sure the bind request is populated. Tracing may have been enabled mid-bind.
if (!m_populatedBindRequest)
PopulateBindRequest(m_bindRequest);
Expand Down Expand Up @@ -246,7 +251,7 @@ namespace BinderTracing

// ActivityTracker or EventSource may have triggered the system satellite load.
// Don't track system satellite binding to avoid potential infinite recursion.
m_ignoreBind = m_bindRequest.AssemblySpec->IsCoreLibSatellite();
m_ignoreBind = m_bindRequest.AssemblySpec->IsCoreLibSatellite() || (t_AssemblyLoadStartInProgress && m_bindRequest.AssemblySpec->IsCoreLib());
davidwrighton marked this conversation as resolved.
Show resolved Hide resolved
m_checkedIgnoreBind = true;
return m_ignoreBind;
}
Expand Down
27 changes: 25 additions & 2 deletions src/tests/tracing/eventpipe/complus_config/name_config_with_pid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ class NameConfigWithPid
{
static int Main(string[] args)
{
if (args.Length == 0)
Console.WriteLine("No Args");
else
Console.WriteLine($"args[0] = `{args[0]}`");

if (args.Length > 0 && args[0] == "waitforinput")
{
Console.Error.WriteLine("WaitingForInput in ErrorStream");
Console.WriteLine("WaitingForInput");
Console.Error.Flush();
Console.Out.Flush();
Console.ReadLine();
return 100;
}
Expand All @@ -31,7 +38,8 @@ static int Main(string[] args)
return 100;
}

string corerun = Path.Combine(Environment.GetEnvironmentVariable("CORE_ROOT"), "corerun");
string coreRoot = Environment.GetEnvironmentVariable("CORE_ROOT");
string corerun = Path.Combine(coreRoot, "corerun");
if (OperatingSystem.IsWindows())
corerun = corerun + ".exe";

Expand All @@ -49,15 +57,30 @@ static int Main(string[] args)
process.StartInfo.Environment.Add("COMPlus_EnableEventPipe", "1");
process.StartInfo.Environment.Add("COMPlus_EventPipeConfig", "Microsoft-Windows-DotNETRuntime:4c14fccbd:4");
process.StartInfo.Environment.Add("COMPlus_EventPipeOutputPath", outputPathPattern);
process.StartInfo.Environment.Add("CORE_ROOT", coreRoot);

Console.WriteLine($"Starting process '{process.StartInfo.FileName}' '{process.StartInfo.Arguments}'");
Console.Out.Flush();
process.Start();

process.StandardError.ReadLine();
string readFromTargetProcess = process.StandardError.ReadLine();
Console.WriteLine($"Readline '{readFromTargetProcess}'");
if (readFromTargetProcess != "WaitingForInput in ErrorStream")
{
Console.WriteLine($"Child process terminating");
Thread.Sleep(10000);
process.Kill();
Console.WriteLine($"Child process terminated");
}
Console.Out.Flush();
uint pid = (uint)process.Id;
string expectedPath = outputPathPattern.Replace("{pid}", pid.ToString());

process.StandardInput.WriteLine("input");
process.StandardInput.Flush();
process.WaitForExit();

Console.WriteLine($"StdErr ReadToEnd from child process '{process.StandardError.ReadToEnd()}'");
if (!File.Exists(expectedPath))
{
Console.WriteLine($"{expectedPath} not found");
Expand Down