Skip to content

Commit 6ffd3bb

Browse files
authored
[nfc][lsan] Restructure loop in ProcessThreads (#112609)
The goal is to move `SuspendedThreadsList` related code into the beginning of the loop, and prepare for extraction the rest of the loop body into a function.
1 parent dd9a34f commit 6ffd3bb

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

compiler-rt/lib/lsan/lsan_common.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,20 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
407407
for (uptr i = 0; i < suspended_threads.ThreadCount(); i++) {
408408
registers.clear();
409409
extra_ranges.clear();
410+
410411
const tid_t os_id = static_cast<tid_t>(suspended_threads.GetThreadID(i));
412+
uptr sp = 0;
413+
PtraceRegistersStatus have_registers =
414+
suspended_threads.GetRegistersAndSP(i, &registers, &sp);
415+
if (have_registers != REGISTERS_AVAILABLE) {
416+
Report("Unable to get registers from thread %llu.\n", os_id);
417+
// If unable to get SP, consider the entire stack to be reachable unless
418+
// GetRegistersAndSP failed with ESRCH.
419+
if (have_registers == REGISTERS_UNAVAILABLE_FATAL)
420+
continue;
421+
sp = 0;
422+
}
423+
411424
LOG_THREADS("Processing thread %llu.\n", os_id);
412425
uptr stack_begin, stack_end, tls_begin, tls_end, cache_begin, cache_end;
413426
DTLS *dtls;
@@ -420,20 +433,13 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
420433
LOG_THREADS("Thread %llu not found in registry.\n", os_id);
421434
continue;
422435
}
423-
uptr sp;
424-
PtraceRegistersStatus have_registers =
425-
suspended_threads.GetRegistersAndSP(i, &registers, &sp);
426-
if (have_registers != REGISTERS_AVAILABLE) {
427-
Report("Unable to get registers from thread %llu.\n", os_id);
428-
// If unable to get SP, consider the entire stack to be reachable unless
429-
// GetRegistersAndSP failed with ESRCH.
430-
if (have_registers == REGISTERS_UNAVAILABLE_FATAL)
431-
continue;
432-
sp = stack_begin;
433-
}
436+
434437
if (os_id == caller_tid)
435438
sp = caller_sp;
436439

440+
if (!sp)
441+
sp = stack_begin;
442+
437443
if (flags()->use_registers && have_registers) {
438444
uptr registers_begin = reinterpret_cast<uptr>(registers.data());
439445
uptr registers_end =

0 commit comments

Comments
 (0)