[ASan] Don't crash in DescribeHeapAddress if we don't know the current thread's ID
Also make DescribeThread easier to use. This was firing on Dr.ASan runs, not sure how to repro InvalidTID in a simple test. llvm-svn: 190392
This commit is contained in:
parent
f16ade7604
commit
190784b21b
|
|
@ -166,6 +166,11 @@ static void PrintZoneForPointer(uptr ptr, uptr zone_ptr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void DescribeThread(AsanThread *t) {
|
||||||
|
if (t)
|
||||||
|
DescribeThread(t->context());
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------- Address Descriptions ------------------- {{{1
|
// ---------------------- Address Descriptions ------------------- {{{1
|
||||||
|
|
||||||
static bool IsASCII(unsigned char c) {
|
static bool IsASCII(unsigned char c) {
|
||||||
|
|
@ -377,7 +382,7 @@ bool DescribeAddressIfStack(uptr addr, uptr access_size) {
|
||||||
Printf("HINT: this may be a false positive if your program uses "
|
Printf("HINT: this may be a false positive if your program uses "
|
||||||
"some custom stack unwind mechanism or swapcontext\n"
|
"some custom stack unwind mechanism or swapcontext\n"
|
||||||
" (longjmp and C++ exceptions *are* supported)\n");
|
" (longjmp and C++ exceptions *are* supported)\n");
|
||||||
DescribeThread(t->context());
|
DescribeThread(t);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -415,13 +420,11 @@ void DescribeHeapAddress(uptr addr, uptr access_size) {
|
||||||
GetThreadContextByTidLocked(chunk.AllocTid());
|
GetThreadContextByTidLocked(chunk.AllocTid());
|
||||||
StackTrace alloc_stack;
|
StackTrace alloc_stack;
|
||||||
chunk.GetAllocStack(&alloc_stack);
|
chunk.GetAllocStack(&alloc_stack);
|
||||||
AsanThread *t = GetCurrentThread();
|
|
||||||
CHECK(t);
|
|
||||||
char tname[128];
|
char tname[128];
|
||||||
Decorator d;
|
Decorator d;
|
||||||
|
AsanThreadContext *free_thread = 0;
|
||||||
if (chunk.FreeTid() != kInvalidTid) {
|
if (chunk.FreeTid() != kInvalidTid) {
|
||||||
AsanThreadContext *free_thread =
|
free_thread = GetThreadContextByTidLocked(chunk.FreeTid());
|
||||||
GetThreadContextByTidLocked(chunk.FreeTid());
|
|
||||||
Printf("%sfreed by thread T%d%s here:%s\n", d.Allocation(),
|
Printf("%sfreed by thread T%d%s here:%s\n", d.Allocation(),
|
||||||
free_thread->tid,
|
free_thread->tid,
|
||||||
ThreadNameWithParenthesis(free_thread, tname, sizeof(tname)),
|
ThreadNameWithParenthesis(free_thread, tname, sizeof(tname)),
|
||||||
|
|
@ -433,19 +436,17 @@ void DescribeHeapAddress(uptr addr, uptr access_size) {
|
||||||
d.Allocation(), alloc_thread->tid,
|
d.Allocation(), alloc_thread->tid,
|
||||||
ThreadNameWithParenthesis(alloc_thread, tname, sizeof(tname)),
|
ThreadNameWithParenthesis(alloc_thread, tname, sizeof(tname)),
|
||||||
d.EndAllocation());
|
d.EndAllocation());
|
||||||
PrintStack(&alloc_stack);
|
|
||||||
DescribeThread(t->context());
|
|
||||||
DescribeThread(free_thread);
|
|
||||||
DescribeThread(alloc_thread);
|
|
||||||
} else {
|
} else {
|
||||||
Printf("%sallocated by thread T%d%s here:%s\n", d.Allocation(),
|
Printf("%sallocated by thread T%d%s here:%s\n", d.Allocation(),
|
||||||
alloc_thread->tid,
|
alloc_thread->tid,
|
||||||
ThreadNameWithParenthesis(alloc_thread, tname, sizeof(tname)),
|
ThreadNameWithParenthesis(alloc_thread, tname, sizeof(tname)),
|
||||||
d.EndAllocation());
|
d.EndAllocation());
|
||||||
PrintStack(&alloc_stack);
|
|
||||||
DescribeThread(t->context());
|
|
||||||
DescribeThread(alloc_thread);
|
|
||||||
}
|
}
|
||||||
|
PrintStack(&alloc_stack);
|
||||||
|
DescribeThread(GetCurrentThread());
|
||||||
|
if (free_thread)
|
||||||
|
DescribeThread(free_thread);
|
||||||
|
DescribeThread(alloc_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescribeAddress(uptr addr, uptr access_size) {
|
void DescribeAddress(uptr addr, uptr access_size) {
|
||||||
|
|
@ -535,10 +536,7 @@ class ScopedInErrorReport {
|
||||||
// Destructor is NORETURN, as functions that report errors are.
|
// Destructor is NORETURN, as functions that report errors are.
|
||||||
NORETURN ~ScopedInErrorReport() {
|
NORETURN ~ScopedInErrorReport() {
|
||||||
// Make sure the current thread is announced.
|
// Make sure the current thread is announced.
|
||||||
AsanThread *curr_thread = GetCurrentThread();
|
DescribeThread(GetCurrentThread());
|
||||||
if (curr_thread) {
|
|
||||||
DescribeThread(curr_thread->context());
|
|
||||||
}
|
|
||||||
// Print memory stats.
|
// Print memory stats.
|
||||||
if (flags()->print_stats)
|
if (flags()->print_stats)
|
||||||
__asan_print_accumulated_stats();
|
__asan_print_accumulated_stats();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue