From d17826e0c88535a9be7c9da257b6fabac62ead4e Mon Sep 17 00:00:00 2001 From: Sung Yoon Whang Date: Wed, 10 Feb 2021 11:54:50 -0800 Subject: [PATCH] Fix dotnet-counters and dotnet-trace CLI arg validator (#1989) * Make the CLI arg validator check for invalid process ID * check for negative PID as well * check for --diagnostic-port as well --- src/Tools/Common/Commands/Utils.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Tools/Common/Commands/Utils.cs b/src/Tools/Common/Commands/Utils.cs index ab161fed2..0d1ee6bb5 100644 --- a/src/Tools/Common/Commands/Utils.cs +++ b/src/Tools/Common/Commands/Utils.cs @@ -53,7 +53,17 @@ namespace Microsoft.Internal.Common.Utils public static bool ValidateArguments(int processId, string name, string port, out int resolvedProcessId) { resolvedProcessId = -1; - if (processId != 0 && name != null && !string.IsNullOrEmpty(port)) + if (processId == 0 && name == null && string.IsNullOrEmpty(port)) + { + Console.WriteLine("Must specify either --process-id, --name, or --diagnostic-port."); + return false; + } + else if (processId < 0) + { + Console.WriteLine($"{processId} is not a valid process ID"); + return false; + } + else if (processId != 0 && name != null && !string.IsNullOrEmpty(port)) { Console.WriteLine("Only one of the --name, --process-id, or --diagnostic-port options may be specified."); return false; -- 2.34.1