Skip to content

Commit c370ac5

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.4
2 parents 37ad65f + c271c48 commit c370ac5

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

compiler-rt/lib/lsan/lsan_common.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,22 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
405405
InternalMmapVector<uptr> registers;
406406
InternalMmapVector<Range> extra_ranges;
407407
for (uptr i = 0; i < suspended_threads.ThreadCount(); i++) {
408-
tid_t os_id = static_cast<tid_t>(suspended_threads.GetThreadID(i));
408+
registers.clear();
409+
extra_ranges.clear();
410+
411+
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+
409424
LOG_THREADS("Processing thread %llu.\n", os_id);
410425
uptr stack_begin, stack_end, tls_begin, tls_end, cache_begin, cache_end;
411426
DTLS *dtls;
@@ -418,20 +433,12 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
418433
LOG_THREADS("Thread %llu not found in registry.\n", os_id);
419434
continue;
420435
}
421-
uptr sp;
422-
PtraceRegistersStatus have_registers =
423-
suspended_threads.GetRegistersAndSP(i, &registers, &sp);
424-
if (have_registers != REGISTERS_AVAILABLE) {
425-
Report("Unable to get registers from thread %llu.\n", os_id);
426-
// If unable to get SP, consider the entire stack to be reachable unless
427-
// GetRegistersAndSP failed with ESRCH.
428-
if (have_registers == REGISTERS_UNAVAILABLE_FATAL)
429-
continue;
430-
sp = stack_begin;
431-
}
432-
if (suspended_threads.GetThreadID(i) == caller_tid) {
436+
437+
if (os_id == caller_tid)
433438
sp = caller_sp;
434-
}
439+
440+
if (!sp)
441+
sp = stack_begin;
435442

436443
if (flags()->use_registers && have_registers) {
437444
uptr registers_begin = reinterpret_cast<uptr>(registers.data());
@@ -464,7 +471,6 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
464471
}
465472
ScanRangeForPointers(stack_begin, stack_end, frontier, "STACK",
466473
kReachable);
467-
extra_ranges.clear();
468474
GetThreadExtraStackRangesLocked(os_id, &extra_ranges);
469475
ScanExtraStackRanges(extra_ranges, frontier);
470476
}

0 commit comments

Comments
 (0)