mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix debug tracing error with magic extents (#25726)
Co-authored-by: Patrick Meinecke <SeeminglyScience@users.noreply.github.com>
This commit is contained in:
co-authored by
Patrick Meinecke
parent
c6329ddd54
commit
ce76ae1def
@@ -1536,7 +1536,16 @@ namespace System.Management.Automation
|
||||
|
||||
internal void OnSequencePointHit(FunctionContext functionContext)
|
||||
{
|
||||
if (_context.ShouldTraceStatement && !_callStack.Last().IsFrameHidden && !functionContext._debuggerStepThrough)
|
||||
// TraceLine uses ColumnNumber and expects it to be 1 based. For
|
||||
// extents added by the engine and not user code the value can be
|
||||
// set to 0 causing an exception. This skips those types of extents
|
||||
// as tracing them wouldn't be useful for the end user anyway.
|
||||
if (_context.ShouldTraceStatement &&
|
||||
!_callStack.Last().IsFrameHidden &&
|
||||
!functionContext._debuggerStepThrough &&
|
||||
functionContext.CurrentPosition is not EmptyScriptExtent &&
|
||||
(functionContext.CurrentPosition is InternalScriptExtent ||
|
||||
functionContext.CurrentPosition.StartColumnNumber > 0))
|
||||
{
|
||||
TraceLine(functionContext.CurrentPosition);
|
||||
}
|
||||
|
||||
@@ -15,5 +15,16 @@ Describe "Set-PSDebug" -Tags "CI" {
|
||||
It "Should be able to set strict" {
|
||||
{ Set-PSDebug -Strict } | Should -Not -Throw
|
||||
}
|
||||
|
||||
It "Should skip magic extents created by pwsh" {
|
||||
class ClassWithDefaultCtor {
|
||||
MyMethod() { }
|
||||
}
|
||||
|
||||
{
|
||||
Set-PSDebug -Trace 1
|
||||
[ClassWithDefaultCtor]::new()
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user