FreeRTOS / FreeRTOS-Kernel

FreeRTOS kernel files only, submoduled into https://github.com/FreeRTOS/FreeRTOS and various other repos.
https://www.FreeRTOS.org
MIT License
2.62k stars 1.09k forks source link

Posix port - set name for threads #950

Closed Mixaill closed 7 months ago

Mixaill commented 7 months ago

Description

Pass the FreeRTOS task name to pthread via pthread_setname_np() for prettier output in debuggers.

Tested on Linux, may need some fixes for macOS / *BSD

image

Test Steps

build any FreeRTOS-based app with posix port and run with attached debug

Checklist:


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Skptak commented 7 months ago

Hey @Mixaill thanks for raising this PR! This does seem useful for debugging, and it seems like a good idea to add this! However, due to a difference in the API for pthread_setname_np() between MacOS and Linux this PR would break MacOS support.

The MacOS version of the function, pthread_setname_np(const char*), doesn't take in a handler to the thread to name. While the Linux verison of the function, pthread_setname_np(pthread_t thread, const char *name), takes in this second argument. This is talked about a bit more in this Github issue. As the POSIX port is meant to be available for MacOS and Linux I'd like this to be something that works and compiles for both.

Maybe an "easy" way to handle this would be to make a wrapper function for pthread_setname_np()? Something like prvPortSetCurrentThreadName(char * pxThreadName), which could then have the necessary check for if the target is apple or linux?

Mixaill commented 7 months ago

@Skptak added support for macOS

codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (52ab3d0) 93.42% compared to head (dabfe24) 93.42%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #950 +/- ## ======================================= Coverage 93.42% 93.42% ======================================= Files 6 6 Lines 3195 3195 Branches 887 887 ======================================= Hits 2985 2985 Misses 103 103 Partials 107 107 ``` | [Flag](https://app.codecov.io/gh/FreeRTOS/FreeRTOS-Kernel/pull/950/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FreeRTOS) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/FreeRTOS/FreeRTOS-Kernel/pull/950/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FreeRTOS) | `93.42% <ø> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FreeRTOS#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

sonarcloud[bot] commented 7 months ago

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud