ValidateResponseMessage(response, nameof(WriteDump));
}
+ /// <summary>
+ /// Trigger a core dump generation.
+ /// </summary>
+ /// <param name="dumpType">Type of the dump to be generated</param>
+ /// <param name="dumpPath">Full path to the dump to be generated. By default it is /tmp/coredump.{pid}</param>
+ /// <param name="flags">logging and crash report flags. On runtimes less than 6.0, only LoggingEnabled is supported.</param>
+ public void WriteDump(DumpType dumpType, string dumpPath, WriteDumpFlags flags)
+ {
+ IpcMessage request = CreateWriteDumpMessage2(dumpType, dumpPath, flags);
+ IpcMessage response = IpcClient.SendMessage(_endpoint, request);
+ if (!ValidateResponseMessage(response, nameof(WriteDump), ValidateResponseOptions.UnknownCommandReturnsFalse))
+ {
+ if ((flags & ~WriteDumpFlags.LoggingEnabled) != 0)
+ {
+ throw new ArgumentException($"Only {nameof(WriteDumpFlags.LoggingEnabled)} flag is supported by this runtime version", nameof(flags));
+ }
+ WriteDump(dumpType, dumpPath, logDumpGeneration: (flags & WriteDumpFlags.LoggingEnabled) != 0);
+ }
+ }
+
/// <summary>
/// Trigger a core dump generation.
/// </summary>
/// <param name="dumpPath">Full path to the dump to be generated. By default it is /tmp/coredump.{pid}</param>
/// <param name="logDumpGeneration">When set to true, display the dump generation debug log to the console.</param>
/// <param name="token">The token to monitor for cancellation requests.</param>
- internal async Task WriteDumpAsync(DumpType dumpType, string dumpPath, bool logDumpGeneration, CancellationToken token)
+ public async Task WriteDumpAsync(DumpType dumpType, string dumpPath, bool logDumpGeneration, CancellationToken token)
{
IpcMessage request = CreateWriteDumpMessage(dumpType, dumpPath, logDumpGeneration);
IpcMessage response = await IpcClient.SendMessageAsync(_endpoint, request, token).ConfigureAwait(false);
ValidateResponseMessage(response, nameof(WriteDumpAsync));
}
+ /// <summary>
+ /// Trigger a core dump generation.
+ /// </summary>
+ /// <param name="dumpType">Type of the dump to be generated</param>
+ /// <param name="dumpPath">Full path to the dump to be generated. By default it is /tmp/coredump.{pid}</param>
+ /// <param name="flags">logging and crash report flags. On runtimes less than 6.0, only LoggingEnabled is supported.</param>
+ /// <param name="token">The token to monitor for cancellation requests.</param>
+ public async Task WriteDumpAsync(DumpType dumpType, string dumpPath, WriteDumpFlags flags, CancellationToken token)
+ {
+ IpcMessage request = CreateWriteDumpMessage2(dumpType, dumpPath, flags);
+ IpcMessage response = await IpcClient.SendMessageAsync(_endpoint, request, token).ConfigureAwait(false);
+ if (!ValidateResponseMessage(response, nameof(WriteDumpAsync), ValidateResponseOptions.UnknownCommandReturnsFalse))
+ {
+ if ((flags & ~WriteDumpFlags.LoggingEnabled) != 0)
+ {
+ throw new ArgumentException($"Only {nameof(WriteDumpFlags.LoggingEnabled)} flag is supported by this runtime version", nameof(flags));
+ }
+ await WriteDumpAsync(dumpType, dumpPath, logDumpGeneration: (flags & WriteDumpFlags.LoggingEnabled) != 0, token);
+ }
+ }
+
/// <summary>
/// Attach a profiler.
/// </summary>
return new IpcMessage(DiagnosticsServerCommandSet.Dump, (byte)DumpCommandId.GenerateCoreDump, payload);
}
+ private static IpcMessage CreateWriteDumpMessage2(DumpType dumpType, string dumpPath, WriteDumpFlags flags)
+ {
+ if (string.IsNullOrEmpty(dumpPath))
+ throw new ArgumentNullException($"{nameof(dumpPath)} required");
+
+ byte[] payload = SerializePayload(dumpPath, (uint)dumpType, (uint)flags);
+ return new IpcMessage(DiagnosticsServerCommandSet.Dump, (byte)DumpCommandId.GenerateCoreDump2, payload);
+ }
+
private static ProcessInfo GetProcessInfoFromResponse(IpcResponse response, string operationName)
{
ValidateResponseMessage(response.Message, operationName);
{
}
- public int Collect(IConsole console, int processId, string output, bool diag, DumpTypeOption type, string name)
+ public int Collect(IConsole console, int processId, string output, bool diag, bool crashreport, DumpTypeOption type, string name)
{
Console.WriteLine(name);
if (name != null)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
+ if (crashreport)
+ {
+ Console.WriteLine("Crash reports not supported on Windows.");
+ return 0;
+ }
+
// Get the process
Process process = Process.GetProcessById(processId);
break;
}
+ WriteDumpFlags flags = WriteDumpFlags.None;
+ if (diag)
+ {
+ flags |= WriteDumpFlags.LoggingEnabled;
+ }
+ if (crashreport)
+ {
+ flags |= WriteDumpFlags.CrashReportEnabled;
+ }
// Send the command to the runtime to initiate the core dump
- client.WriteDump(dumpType, output, diag);
+ client.WriteDump(dumpType, output, flags);
}
}
catch (Exception ex) when
new Command( name: "collect", description: "Capture dumps from a process")
{
// Handler
- CommandHandler.Create<IConsole, int, string, bool, Dumper.DumpTypeOption, string>(new Dumper().Collect),
+ CommandHandler.Create<IConsole, int, string, bool, bool, Dumper.DumpTypeOption, string>(new Dumper().Collect),
// Options
- ProcessIdOption(), OutputOption(), DiagnosticLoggingOption(), TypeOption(), ProcessNameOption()
+ ProcessIdOption(), OutputOption(), DiagnosticLoggingOption(), CrashReportOption(), TypeOption(), ProcessNameOption()
};
private static Option ProcessIdOption() =>
Argument = new Argument<bool>(name: "diag")
};
+ private static Option CrashReportOption() =>
+ new Option(
+ alias: "--crashreport",
+ description: "Enable crash report generation.")
+ {
+ Argument = new Argument<bool>(name: "crashreport")
+ };
+
private static Option TypeOption() =>
new Option(
alias: "--type",