Skip to content

Commit

Permalink
[nfc][lsan] Restructure loop in ProcessThreads (#112609)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vitalybuka authored Oct 17, 2024
1 parent dd9a34f commit 6ffd3bb
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions compiler-rt/lib/lsan/lsan_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,20 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
for (uptr i = 0; i < suspended_threads.ThreadCount(); i++) {
registers.clear();
extra_ranges.clear();

const tid_t os_id = static_cast<tid_t>(suspended_threads.GetThreadID(i));
uptr sp = 0;
PtraceRegistersStatus have_registers =
suspended_threads.GetRegistersAndSP(i, &registers, &sp);
if (have_registers != REGISTERS_AVAILABLE) {
Report("Unable to get registers from thread %llu.\n", os_id);
// If unable to get SP, consider the entire stack to be reachable unless
// GetRegistersAndSP failed with ESRCH.
if (have_registers == REGISTERS_UNAVAILABLE_FATAL)
continue;
sp = 0;
}

LOG_THREADS("Processing thread %llu.\n", os_id);
uptr stack_begin, stack_end, tls_begin, tls_end, cache_begin, cache_end;
DTLS *dtls;
Expand All @@ -420,20 +433,13 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
LOG_THREADS("Thread %llu not found in registry.\n", os_id);
continue;
}
uptr sp;
PtraceRegistersStatus have_registers =
suspended_threads.GetRegistersAndSP(i, &registers, &sp);
if (have_registers != REGISTERS_AVAILABLE) {
Report("Unable to get registers from thread %llu.\n", os_id);
// If unable to get SP, consider the entire stack to be reachable unless
// GetRegistersAndSP failed with ESRCH.
if (have_registers == REGISTERS_UNAVAILABLE_FATAL)
continue;
sp = stack_begin;
}

if (os_id == caller_tid)
sp = caller_sp;

if (!sp)
sp = stack_begin;

if (flags()->use_registers && have_registers) {
uptr registers_begin = reinterpret_cast<uptr>(registers.data());
uptr registers_end =
Expand Down

0 comments on commit 6ffd3bb

Please sign in to comment.