Skip to content

Conversation

@elliette
Copy link
Member

Fixes #9526

Fixes bug in implementation of getResolvedUrl which was throwing an index out of range error when advanced developer mode was enabled.

  String? get resolvedUrl => isCodeTree && _function is vm_service.FuncRef?
      ?
        (_function as vm_service.FuncRef?)?.location?.script?.uri
      : samples.functions?[index].resolvedUrl;

When advanced developer mode is enabled, the CPU profile also includes the code tree. Therefore, in the original ternary, isCodeTree is true. The issue happened when _function is vm_service.FuncRef? was false. Then we would fall back to the false case in the ternary. We would then try to index into the profile's functions list with an index that was actually intended for the code objects list.

@elliette elliette requested review from a team, bkonyi and kenzieschmoll as code owners November 21, 2025 23:06
@elliette elliette requested review from jakemac53 and removed request for bkonyi and kenzieschmoll November 21, 2025 23:06
}
} else {
final functions = samples.functions;
if (functions == null || index >= functions.length) return null;
Copy link
Member Author

Choose a reason for hiding this comment

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

This check index >= functions.length is not strictly necessary but I want to be extra safe.

"tid": 100,
"timestamp": 50,
"stack": [0, 1],
"_codeStack": [2]
Copy link
Member Author

Choose a reason for hiding this comment

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

Before the change, the regression test would fail because we would try to index into functions[2] which only has 2 items

Copy link
Contributor

@jakemac53 jakemac53 left a comment

Choose a reason for hiding this comment

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

🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CPU Profiler is broken when "Advanced Developer Mode" is enabled

2 participants