Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/System.Management.Automation/engine/debugger/debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,16 @@ private List<Breakpoint> TriggerBreakpoints(List<Breakpoint> breakpoints)

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the test really throw before the fix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run it yourself and see :)

}
}
}
Loading