Repository: dotnet/runtime
File: src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.cpp (C++)

Code before:
	STATIC_CONTRACT_NOTHROW;
	EP_ASSERT (frame != NULL);
	EP_ASSERT (stack_contents != NULL);

	// Get the IP.
	UINT_PTR control_pc = (UINT_PTR)frame->GetRegisterSet ()->ControlPC;
	
	if (!frame->IsFrameless() && frame->GetFrame()->GetFrameIdentifier() == FrameIdentifier::PrestubMethodFrame) {
		// At the PrestubMethodFrame, the ControlPC is not valid. Instead use the address of the Prestub.
		control_pc = 0;
	}
	if (control_pc == 0) {
#ifdef DEBUG
		if (ep_stack_contents_get_length (stack_contents) == 0) {
			// This happens for pinvoke stubs on the top of the stack.
		}
		else if (!frame->IsFrameless() && frame->GetFrame()->GetFrameIdentifier() == FrameIdentifier::PrestubMethodFrame) {
			// This happens for PrestubMethodFrame when we have interpreter frames on the stack
			// In non-interpreter scenarios the control_pc is not set to anything meaningful, but reporting it doesn't seem to cause problems.
		}
		else {
			EP_ASSERT (!"Unexpected null ControlPC in stack walk callback");
		}
#endif
		// With FUNCTIONSONLY flag, we may hit frames without a meaningful control_pc, but with a valid MethodDesc.
		// there is no point in reporting those frames as ep_stack_contents_append doesn't actually record the function
		// in a Frame in release builds, it only records the control_pc.
		return SWA_CONTINUE;
	}

	EP_ASSERT (control_pc != 0);

	// Add the IP to the captured stack.
	ep_stack_contents_append (stack_contents, control_pc, frame->GetFunction ());

	// Continue the stack walk.
	return SWA_CONTINUE;
}

bool
ep_rt_coreclr_walk_managed_stack_for_thread (
	ep_rt_thread_handle_t thread,
	EventPipeStackContents *stack_contents)
{
	STATIC_CONTRACT_NOTHROW;
	EP_ASSERT (thread != NULL);
	EP_ASSERT (stack_contents != NULL);

	// Before we call into StackWalkFrames we need to mark GC_ON_TRANSITIONS as FALSE
	// because under GCStress runs (GCStress=0x3), a GC will be triggered for every transition,
	// which will cause the GC to try to walk the stack while we are in the middle of walking the stack.

Review comment (suggestion):
The comment uses lowercase "there" at the start of the sentence. It should be capitalized: "There is no point in reporting those frames..."
```suggestion
		// There is no point in reporting those frames as ep_stack_contents_append doesn't actually record the function
```

Code after:
	STATIC_CONTRACT_NOTHROW;
	EP_ASSERT (frame != NULL);
	EP_ASSERT (stack_contents != NULL);

	// Get the IP.
	UINT_PTR control_pc = (UINT_PTR)frame->GetRegisterSet ()->ControlPC;
	
	if (!frame->IsFrameless() && frame->GetFrame()->GetFrameIdentifier() == FrameIdentifier::PrestubMethodFrame) {
		// At the PrestubMethodFrame, the ControlPC is not valid. Since the eventpipe stackwalk is actually only based on the ip, skip this frame.
		return SWA_CONTINUE;
	}
	if (control_pc == 0) {
#ifdef DEBUG
		if (ep_stack_contents_get_length (stack_contents) == 0) {
			// This happens for pinvoke stubs on the top of the stack.
		}
		else {
			EP_ASSERT (!"Unexpected null ControlPC in stack walk callback");
		}
#endif
		// With FUNCTIONSONLY flag, we may hit frames without a meaningful control_pc, but with a valid MethodDesc.
		// There is no point in reporting those frames as ep_stack_contents_append doesn't actually record the function
		// in a Frame in release builds, it only records the control_pc.
		return SWA_CONTINUE;
	}

	EP_ASSERT (control_pc != 0);

	// Add the IP to the captured stack.
	ep_stack_contents_append (stack_contents, control_pc, frame->GetFunction ());

	// Continue the stack walk.
	return SWA_CONTINUE;
}

bool
ep_rt_coreclr_walk_managed_stack_for_thread (
	ep_rt_thread_handle_t thread,
	EventPipeStackContents *stack_contents)
{
	STATIC_CONTRACT_NOTHROW;
	EP_ASSERT (thread != NULL);
	EP_ASSERT (stack_contents != NULL);

	// Before we call into StackWalkFrames we need to mark GC_ON_TRANSITIONS as FALSE
	// because under GCStress runs (GCStress=0x3), a GC will be triggered for every transition,
	// which will cause the GC to try to walk the stack while we are in the middle of walking the stack.
	bool gc_on_transitions = GC_ON_TRANSITIONS (FALSE);

	StackWalkAction result = thread->StackWalkFrames (
		(PSTACKWALKFRAMESCALLBACK)stack_walk_callback,