From d460c8c8890f2ed087b25280cc83df72364a5b5d Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Tue, 21 Mar 2023 10:23:03 -0700 Subject: [PATCH] Make PSReadLine script hidden from debugger --- PSReadLine/PSReadLine.psm1 | 3 +++ PSReadLine/ReadLine.cs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/PSReadLine/PSReadLine.psm1 b/PSReadLine/PSReadLine.psm1 index 74c27141..572aee80 100644 --- a/PSReadLine/PSReadLine.psm1 +++ b/PSReadLine/PSReadLine.psm1 @@ -1,5 +1,8 @@ function PSConsoleHostReadLine { + [System.Diagnostics.DebuggerHidden()] + param() + ## Get the execution status of the last accepted user input. ## This needs to be done as the first thing because any script run will flush $?. $lastRunStatus = $? diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index a6010bb9..33b65d06 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -238,7 +238,7 @@ internal static PSKeyInfo ReadKey() if (ps == null) { ps = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace); - ps.AddScript("0", useLocalScope: true); + ps.AddScript("[System.Diagnostics.DebuggerHidden()]param() 0", useLocalScope: true); } // To detect output during possible event processing, see if the cursor moved @@ -674,7 +674,7 @@ private PSConsoleReadLine() { try { - var results = ps.AddScript("$Host", useLocalScope: true).Invoke(); + var results = ps.AddScript("[System.Diagnostics.DebuggerHidden()]param() $Host", useLocalScope: true).Invoke(); PSHost host = results.Count == 1 ? results[0] : null; hostName = host?.Name; }