Skip to content
Permalink
Browse files

add live (Passive) data reader for Linux (#263)

* add Linux live data reader

* add Docker sample

* update dockerfile

* add data size limit based on memory region

* check for file exists

* remove sample

* clean up comments

* add conditional compilation for NET45

* incorporate review feedbacks

* incorporate feedbacksy
  • Loading branch information...
xinyanmsft authored and leculver committed May 10, 2019
1 parent 5b6ff59 commit b1c94e5a9643b35f846da16a95f8e0ec63a3e785
@@ -132,7 +132,22 @@ public static DataTarget AttachToProcess(int pid, uint msecTimeout, AttachFlag a
IDataReader reader;
if (attachFlag == AttachFlag.Passive)
{
#if NET45
reader = new LiveDataReader(pid, false);
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
reader = new LiveDataReader(pid, false);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
reader = new Linux.LinuxLiveDataReader((uint) pid);
}
else
{
throw new NotSupportedException("Passive attach is not supported on OSX.s");
}
#endif
}
else
{
@@ -142,6 +157,15 @@ public static DataTarget AttachToProcess(int pid, uint msecTimeout, AttachFlag a
}

DataTargetImpl dataTarget = new DataTargetImpl(reader, client);
#if !NET45
if (reader is Linux.LinuxLiveDataReader)
{
// TODO: discuss this design of
// 1) add a method to IDataReader2 to return the list of module full path
// 2) make DefaultSymbolLocator use that list as hint to load binaries
dataTarget.SymbolLocator = new Linux.LinuxDefaultSymbolLocator(((Linux.LinuxLiveDataReader) reader).GetModulesFullPath());
}
#endif
return dataTarget;
}

@@ -0,0 +1,44 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Diagnostics.Runtime;
using Microsoft.Diagnostics.Runtime.Utilities;

namespace Microsoft.Diagnostics.Runtime.Linux
{
/// <summary>
/// A symbol locator that search binaries based on files loaded in the live Linux target.
/// </summary>
internal class LinuxDefaultSymbolLocator : DefaultSymbolLocator
{
private IEnumerable<string> _modules;

public LinuxDefaultSymbolLocator(IEnumerable<string> modules) : base()
{
_modules = modules;
}

public override string FindBinary(string fileName, int buildTimeStamp, int imageSize, bool checkProperties = true)
{
string name = Path.GetFileName(fileName);
foreach(var m in _modules)
{
if (name == Path.GetFileName(m))
{
return m;
}
string path = Path.Combine(Path.GetDirectoryName(m), name);
if (File.Exists(path))
{
return path;
}
}
return base.FindBinary(fileName, buildTimeStamp, imageSize, checkProperties);
}
}
}

0 comments on commit b1c94e5

Please sign in to comment.
You can’t perform that action at this time.