[asan] if verbosity>=2, print the fake stack usage stats at thread exit; No functionality change in non-verboze mode

llvm-svn: 197037
This commit is contained in:
Kostya Serebryany 2013-12-11 13:54:01 +00:00
parent e1468322eb
commit 7a3a93f112
5 changed files with 19 additions and 11 deletions

View File

@ -52,8 +52,15 @@ FakeStack *FakeStack::Create(uptr stack_size_log) {
return res;
}
void FakeStack::Destroy() {
void FakeStack::Destroy(int tid) {
PoisonAll(0);
if (common_flags()->verbosity >= 2) {
InternalScopedString str(kNumberOfSizeClasses * 50);
for (uptr class_id = 0; class_id < kNumberOfSizeClasses; class_id++)
str.append("%zd: %zd/%zd; ", class_id, hint_position_[class_id],
NumberOfFrames(stack_size_log(), class_id));
Report("T%d: FakeStack destroyed: %s\n", tid, str.data());
}
UnmapOrDie(this, RequiredSize(stack_size_log_));
}

View File

@ -65,7 +65,7 @@ class FakeStack {
// CTOR: create the FakeStack as a single mmap-ed object.
static FakeStack *Create(uptr stack_size_log);
void Destroy();
void Destroy(int tid);
// stack_size_log is at least 15 (stack_size >= 32K).
static uptr SizeRequiredForFlags(uptr stack_size_log) {

View File

@ -93,17 +93,18 @@ void AsanThread::TSDDtor(void *tsd) {
}
void AsanThread::Destroy() {
VReport(1, "T%d exited\n", tid());
int tid = this->tid();
VReport(1, "T%d exited\n", tid);
malloc_storage().CommitBack();
if (flags()->use_sigaltstack) UnsetAlternateSignalStack();
asanThreadRegistry().FinishThread(tid());
asanThreadRegistry().FinishThread(tid);
FlushToDeadThreadStats(&stats_);
// We also clear the shadow on thread destruction because
// some code may still be executing in later TSD destructors
// and we don't want it to have any poisoned stack.
ClearShadowForThreadStackAndTLS();
DeleteFakeStack();
DeleteFakeStack(tid);
uptr size = RoundUpTo(sizeof(AsanThread), GetPageSizeCached());
UnmapOrDie(this, size);
}

View File

@ -78,12 +78,12 @@ class AsanThread {
return addr >= stack_bottom_ && addr < stack_top_;
}
void DeleteFakeStack() {
void DeleteFakeStack(int tid) {
if (!fake_stack_) return;
FakeStack *t = fake_stack_;
fake_stack_ = 0;
SetTLSFakeStack(0);
t->Destroy();
t->Destroy(tid);
}
bool has_fake_stack() {

View File

@ -63,7 +63,7 @@ TEST(FakeStack, CreateDestroy) {
for (int i = 0; i < 1000; i++) {
for (uptr stack_size_log = 20; stack_size_log <= 22; stack_size_log++) {
FakeStack *fake_stack = FakeStack::Create(stack_size_log);
fake_stack->Destroy();
fake_stack->Destroy(0);
}
}
}
@ -98,7 +98,7 @@ TEST(FakeStack, GetFrame) {
EXPECT_EQ(base + 0*stack_size + 64 * 7, fs->GetFrame(stack_size_log, 0, 7U));
EXPECT_EQ(base + 1*stack_size + 128 * 3, fs->GetFrame(stack_size_log, 1, 3U));
EXPECT_EQ(base + 2*stack_size + 256 * 5, fs->GetFrame(stack_size_log, 2, 5U));
fs->Destroy();
fs->Destroy(0);
}
TEST(FakeStack, Allocate) {
@ -127,7 +127,7 @@ TEST(FakeStack, Allocate) {
fs->Deallocate(reinterpret_cast<uptr>(it->first), it->second);
}
}
fs->Destroy();
fs->Destroy(0);
}
static void RecursiveFunction(FakeStack *fs, int depth) {
@ -144,7 +144,7 @@ TEST(FakeStack, RecursiveStressTest) {
const uptr stack_size_log = 16;
FakeStack *fs = FakeStack::Create(stack_size_log);
RecursiveFunction(fs, 22); // with 26 runs for 2-3 seconds.
fs->Destroy();
fs->Destroy(0);
}
} // namespace __asan