Summary: Adds two flavours of generic unwinder and all the supporting cruft. If the supporting allocator is okay with bringing in sanitizer_common, they can use the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also provide the backtrace() libc-based unwinder as well. Of course, the allocator can always specify its own unwinder and unwinder-symbolizer. The slightly changed output format is exemplified in the first comment on this patch. It now better incorporates backtrace information, and displays allocation details on the second line. Reviewers: eugenis, vlad.tsyrklevich Reviewed By: eugenis, vlad.tsyrklevich Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D63841 llvm-svn: 364941
42 lines
1.3 KiB
C++
42 lines
1.3 KiB
C++
//===-- backtrace.cc --------------------------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include <string>
|
|
|
|
#include "gwp_asan/tests/harness.h"
|
|
|
|
TEST_F(BacktraceGuardedPoolAllocator, DoubleFree) {
|
|
void *Ptr = GPA.allocate(1);
|
|
GPA.deallocate(Ptr);
|
|
|
|
std::string DeathRegex = "Double free.*";
|
|
DeathRegex.append("backtrace\\.cpp:25.*");
|
|
|
|
DeathRegex.append("was deallocated.*");
|
|
DeathRegex.append("backtrace\\.cpp:15.*");
|
|
|
|
DeathRegex.append("was allocated.*");
|
|
DeathRegex.append("backtrace\\.cpp:14.*");
|
|
ASSERT_DEATH(GPA.deallocate(Ptr), DeathRegex);
|
|
}
|
|
|
|
TEST_F(BacktraceGuardedPoolAllocator, UseAfterFree) {
|
|
char *Ptr = static_cast<char *>(GPA.allocate(1));
|
|
GPA.deallocate(Ptr);
|
|
|
|
std::string DeathRegex = "Use after free.*";
|
|
DeathRegex.append("backtrace\\.cpp:40.*");
|
|
|
|
DeathRegex.append("was deallocated.*");
|
|
DeathRegex.append("backtrace\\.cpp:30.*");
|
|
|
|
DeathRegex.append("was allocated.*");
|
|
DeathRegex.append("backtrace\\.cpp:29.*");
|
|
ASSERT_DEATH({ *Ptr = 7; }, DeathRegex);
|
|
}
|