Skip to content

[sanitizer] VReport thread status for failed PTRACE_ATTACH #111901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,6 @@ ThreadLister::Result ThreadLister::ListThreads(

Result result = Ok;
for (bool first_read = true;; first_read = false) {
// Resize to max capacity if it was downsized by IsAlive.
buffer_.resize(buffer_.capacity());
CHECK_GE(buffer_.size(), 4096);
uptr read = internal_getdents(
descriptor, (struct linux_dirent *)buffer_.data(), buffer_.size());
Expand Down Expand Up @@ -1088,14 +1086,25 @@ ThreadLister::Result ThreadLister::ListThreads(
}
}

const char *ThreadLister::LoadStatus(int tid) {
auto cleanup = at_scope_exit([&] {
// Resize back to capacity if it is downsized by `ReadFileToVector`.
buffer_.resize(buffer_.capacity());
});
if (!ReadFileToVector(status_path_.data(), &buffer_) || buffer_.empty())
return nullptr;
buffer_.push_back('\0');
return buffer_.data();
}

bool ThreadLister::IsAlive(int tid) {
// /proc/%d/task/%d/status uses same call to detect alive threads as
// proc_task_readdir. See task_state implementation in Linux.
if (!ReadFileToVector(status_path_.data(), &buffer_) || buffer_.empty())
return false;
buffer_.push_back(0);
static const char kPrefix[] = "\nPPid:";
const char *field = internal_strstr(buffer_.data(), kPrefix);
const char *status = LoadStatus(tid);
if (!status)
return false;
const char *field = internal_strstr(status, kPrefix);
if (!field)
return false;
field += internal_strlen(kPrefix);
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class ThreadLister {
Ok,
};
Result ListThreads(InternalMmapVector<tid_t> *threads);
const char *LoadStatus(int tid);

private:
bool IsAlive(int tid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ bool ThreadSuspender::SuspendAllThreads() {
for (tid_t tid : threads) {
if (SuspendThread(tid))
retry = true;
else
VReport(2, "%llu/status: %s\n", tid, thread_lister.LoadStatus(tid));
}
if (retry)
VReport(1, "SuspendAllThreads retry: %d\n", i);
Expand Down
Loading