Skip to content

Commit cdfd2a1

Browse files
committed
Make it easier to see which threads aren't suspended
I have created a g_threadNamesToIgnore[] array at the top of ThreadDebug.cpp listing the names of the threads not to be suspended when a debug event occurs. Currently the list only contains "rtx_idle". Before the list was hardcoded in the suspendAllApplicationThreads() function, where it was hard for maintainers to find.
1 parent e383a51 commit cdfd2a1

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

Diff for: libraries/ThreadDebug/src/ThreadDebug.cpp

+27-5
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,20 @@ extern "C"
3636
}
3737

3838

39+
// ---------------------------------------------------------------------------------------------------------------------
3940
// Configuration Parameters
41+
// ---------------------------------------------------------------------------------------------------------------------
4042
// The size of the mriThread() stack in uint64_t objects.
4143
#define MRI_THREAD_STACK_SIZE 128
4244
// The maximum number of active threads that can be handled by the debugger.
4345
#define MAXIMUM_ACTIVE_THREADS 64
4446

47+
// Threads with these names will not be suspended when a debug event is occurred.
48+
// Typically these will be threads used by the communication stack to communicate with GDB or other important system
49+
// threads.
50+
static const char* g_threadNamesToIgnore[] = {
51+
"rtx_idle"
52+
};
4553

4654

4755

@@ -149,6 +157,7 @@ extern "C" void mriSysTickHandlerStub(void);
149157
// Forward Function Declarations
150158
static __NO_RETURN void mriMain(void *pv);
151159
static void suspendAllApplicationThreads();
160+
static bool isThreadToIgnore(osThreadId_t thread);
152161
static void resumeApplicationThreads();
153162
static void readThreadContext(osThreadId_t thread);
154163
static void switchRtxHandlersToDebugStubsForSingleStepping();
@@ -245,15 +254,28 @@ static void suspendAllApplicationThreads()
245254
osThreadEnumerate(g_suspendedThreads, sizeof(g_suspendedThreads)/sizeof(g_suspendedThreads[0]));
246255
for (uint32_t i = 0 ; i < g_threadCount ; i++) {
247256
osThreadId_t thread = g_suspendedThreads[i];
248-
const char* pThreadName = osThreadGetName(thread);
249-
250-
if (thread != mriThreadId && strcmp(pThreadName, "rtx_idle") != 0) {
257+
if (isThreadToIgnore(thread)) {
258+
g_suspendedThreads[i] = 0;
259+
} else {
251260
osThreadSuspend(thread);
252261
}
253-
else {
254-
g_suspendedThreads[i] = 0;
262+
}
263+
}
264+
265+
static bool isThreadToIgnore(osThreadId_t thread)
266+
{
267+
if (thread == mriThreadId) {
268+
// Don't want to suspend the debugger thread itself.
269+
return true;
270+
}
271+
272+
const char* pThreadName = osThreadGetName(thread);
273+
for (size_t i = 0 ; i < sizeof(g_threadNamesToIgnore)/sizeof(g_threadNamesToIgnore[0]) ; i++) {
274+
if (strcmp(pThreadName, g_threadNamesToIgnore[i]) == 0) {
275+
return true;
255276
}
256277
}
278+
return false;
257279
}
258280

259281
static void resumeApplicationThreads()

0 commit comments

Comments
 (0)