-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bootstrapper to auto-detect runtime arch.
- Loading branch information
Showing
4 changed files
with
75 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Library</OutputType> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net461</TargetFramework> | ||
<Version>1.1.0</Version> | ||
<Version>1.2.0</Version> | ||
<Title>ClrStack</Title> | ||
<Authors>Mikhail Filippov</Authors> | ||
<Description>Tool for capturing managed stack traces from .NET applications.</Description> | ||
<Description>Tool for capturing managed stack traces from .NET applications.</Description> | ||
<PackageLicenseUrl>https://github.com/mfilippov/clrstack/blob/master/LICENSE</PackageLicenseUrl> | ||
<PackageProjectUrl>https://github.com/mfilippov/clrstack</PackageProjectUrl> | ||
<RepositoryUrl>https://github.com/mfilippov/clrstack</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<Copyright>Mikhail Filippov</Copyright> | ||
<OutputPath>..\build</OutputPath> | ||
<IncludeBuildOutput>False</IncludeBuildOutput> | ||
<OutputPath>..\..\build</OutputPath> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<None Include="..\build\net461\ClrStack.x64.exe" Pack="True" PackagePath="."/> | ||
<None Include="..\build\net461\ClrStack.x86.exe" Pack="True" PackagePath="."/> | ||
<None Include="..\build\net461\Microsoft.Diagnostics.Runtime.dll" Pack="True" PackagePath="."/> | ||
<ItemGroup> | ||
<None Include="..\build\net461\ClrStack.x64.exe" Pack="True" PackagePath=".\lib\net461"/> | ||
<None Include="..\build\net461\ClrStack.x86.exe" Pack="True" PackagePath=".\lib\net461"/> | ||
<None Include="..\build\net461\Microsoft.Diagnostics.Runtime.dll" Pack="True" PackagePath=".\lib\net461"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\ClrStack.x64\ClrStack.x64.csproj"> | ||
<ReferenceOutputAssembly>False</ReferenceOutputAssembly> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</ProjectReference> | ||
<ProjectReference Include="..\ClrStack.x86\ClrStack.x86.csproj"> | ||
<ReferenceOutputAssembly>False</ReferenceOutputAssembly> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="0.9.180305.1" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace ClrStack | ||
{ | ||
public static class Program | ||
{ | ||
[DllImport("kernel32.dll", SetLastError = true)] | ||
private static extern bool IsWow64Process(IntPtr hProcess, out bool isWow64Process); | ||
|
||
public static void Main(string[] args) | ||
{ | ||
if (args.Length != 1 || | ||
!int.TryParse(args[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out var pid)) | ||
{ | ||
Console.Error.WriteLine("Usage: ClrStack.exe [PID]"); | ||
return; | ||
} | ||
var targetProcess = Process.GetProcessById(pid); | ||
var archSuffix = Is64BitProcess(targetProcess) ? "x64" : "x86"; | ||
var platformSpecificExecutable = $"ClrStack.{archSuffix}.exe"; | ||
var assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
var fullPath = assemblyDirectory != null | ||
? Path.Combine(assemblyDirectory, platformSpecificExecutable) | ||
: platformSpecificExecutable; | ||
var process = new Process | ||
{ | ||
StartInfo = new ProcessStartInfo(fullPath, pid.ToString()) | ||
{ | ||
CreateNoWindow = true, | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true, | ||
UseShellExecute = false | ||
} | ||
}; | ||
process.OutputDataReceived += (sender, eventArgs) => Console.WriteLine(eventArgs.Data); | ||
process.ErrorDataReceived += (sender, eventArgs) => Console.WriteLine(eventArgs.Data); | ||
process.Start(); | ||
process.BeginOutputReadLine(); | ||
process.BeginErrorReadLine(); | ||
process.WaitForExit(); | ||
process.CancelOutputRead(); | ||
process.CancelErrorRead(); | ||
} | ||
|
||
private static bool Is64BitProcess(Process process) | ||
{ | ||
if (!Environment.Is64BitOperatingSystem) | ||
return false; | ||
IsWow64Process(process.Handle, out var isWow64Process); | ||
return !isWow64Process; | ||
} | ||
} | ||
} |