Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] fix thread names in debugger / crash dumps #23204

Merged
merged 3 commits into from
May 6, 2023

Conversation

CrystalP
Copy link
Contributor

@CrystalP CrystalP commented Apr 26, 2023

Description

Fixed up / updated the way thread names are set so they can be seen in the debugger.

  • The legacy method used by Kodi so far needed a thread id instead of a thread handle (all Windows platforms)

  • Added the modern method SetThreadDescription available with Windows 10 1607 and above. The new method adds a few niceties, see https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code?view=vs-2022

    • Both method can coexist, but might as well use only the new one when available, with fallback to the legacy method.

    • The new method requires dynamic loading as the function does not exist in older versions of Windows
      To avoid impacting performance, LoadLibrary/GetProcAddress is done once and a cached pointer is used for every new thread. Could be simplified if thread creation time is a non-issue.

    • No support added for UWP (covered by legacy method). I'm not familiar with Win RT and didn't find an equivalent that didn't require bundling KernelBase.dll with the app, most likely not a good idea.

  • Had to define new Windows builds in order to detect Windows 10 1607 properly

Motivation and context

Generic thread names in the debugger make debugging more difficult.

How has this been tested?

Windows 10 22H2 x64 and UWP x64. With old method and new method enabled selectively by special code not included in PR.

What is the effect on users?

none

Screenshots (if appropriate):

Before, generic names assigned by Visual Studio:
image

After, Kodi specified names:
image

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • None of the above (please explain below)

Checklist:

  • My code follows the Code Guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the Contributing document
  • I have added tests to cover my change
  • All new and existing tests passed

@CrystalP CrystalP added Type: Fix non-breaking change which fixes an issue Type: Improvement non-breaking change which improves existing functionality Platform: Windows Platform: WindowsStore Component: Logging v21 Omega labels Apr 26, 2023
@CrystalP CrystalP added this to the Omega 21.0 Alpha 2 milestone Apr 26, 2023
Copy link
Member

@thexai thexai left a comment

Choose a reason for hiding this comment

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

Maybe worth backport fix commit only to Nexus

DWORD dwType; // must be 0x1000
LPCSTR szName; // pointer to name (in same addr space)
DWORD dwThreadID; // thread ID (-1 caller thread)
DWORD dwFlags; // reserved for future use, most be zero
Copy link
Member

Choose a reason for hiding this comment

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

"must be zero"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes done

@CrystalP
Copy link
Contributor Author

Maybe worth backport fix commit only to Nexus
That commit is low risk, why not. I'd have to do a PR against the Nexus branch?

@thexai
Copy link
Member

thexai commented Apr 28, 2023

Yes a new PR against the Nexus with only commit:
"[Windows] fix thread naming in debugger (needs thread id not thread handle)"

(cherry pick same commit)

And if you want also can do the same with: #23017

@CrystalP
Copy link
Contributor Author

@garbear OK with merge?

@CrystalP
Copy link
Contributor Author

CrystalP commented May 6, 2023

@garbear OK with you to merge?

@CrystalP CrystalP merged commit a46a420 into xbmc:master May 6, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backport: Done Component: Logging Platform: Windows Platform: WindowsStore Type: Fix non-breaking change which fixes an issue Type: Improvement non-breaking change which improves existing functionality v21 Omega
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants