diff options
author | Filipe Cabecinhas <me@filcab.net> | 2016-08-30 17:08:55 +0000 |
---|---|---|
committer | Filipe Cabecinhas <me@filcab.net> | 2016-08-30 17:08:55 +0000 |
commit | 43044ab0d65bccde7cd7f8377fe31a52dd3388f1 (patch) | |
tree | b6fdfdaa34286d9b295f6f37ece09ee128521b5d /lib/asan/asan_errors.h | |
parent | 9444a2395b8c807189b39585ce0a0ccea70b32f3 (diff) | |
download | compiler-rt-43044ab0d65bccde7cd7f8377fe31a52dd3388f1.tar.gz |
Start reifying error descriptions (Re-do of D23672 supporting VS2013)
Summary:
@kcc: I know you've accepted the other revision, but since this is a
non-trivial change, I'm updating it to show why D24029 would help.
This commit sets up the infrastructure to use reified error
descriptions, and moves ReportStackOverflow to the new system.
After we convert all the errors, we'll be able to simplify ScopedInErrorReport
and remove the older debugging mechanism which had some errors partly reified
in some way. We'll be able to maintain the external API.
ScopedInErrorReport will be able to track one of the reified errors at a time.
The purpose of this is so we have its destructor actually print the error and
possibly interface with the debugger (will depend on the platform, of course).
Reviewers: kcc, samsonov, timurrrr
Subscribers: kcc, llvm-commits, kubabrecka
Differential Revision: https://reviews.llvm.org/D24030
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@280111 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/asan/asan_errors.h')
-rw-r--r-- | lib/asan/asan_errors.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/asan/asan_errors.h b/lib/asan/asan_errors.h new file mode 100644 index 000000000..87bc8690f --- /dev/null +++ b/lib/asan/asan_errors.h @@ -0,0 +1,82 @@ +//===-- asan_errors.h -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// ASan-private header for error structures. +//===----------------------------------------------------------------------===// +#ifndef ASAN_ERRORS_H +#define ASAN_ERRORS_H + +#include "asan_descriptions.h" +#include "asan_scariness_score.h" + +namespace __asan { + +struct ErrorBase { + ScarinessScoreBase scariness; +}; + +struct ErrorStackOverflow : ErrorBase { + u32 tid; + uptr addr, pc, bp, sp; + // ErrorStackOverflow never owns the context. + void *context; + // VS2013 doesn't implement unrestricted unions, so we need a trivial default + // constructor + ErrorStackOverflow() = default; + ErrorStackOverflow(const SignalContext &sig, u32 tid_) + : tid(tid_), + addr(sig.addr), + pc(sig.pc), + bp(sig.bp), + sp(sig.sp), + context(sig.context) { + scariness.Clear(); + scariness.Scare(10, "stack-overflow"); + } + void Print(); +}; + +enum ErrorKind { + kErrorKindInvalid = 0, + kErrorKindStackOverflow, +}; + +struct ErrorDescription { + ErrorKind kind; + // We're using a tagged union because it allows us to have a trivially + // copiable type and use the same structures as the public interface. + // + // We can add a wrapper around it to make it "more c++-like", but that would + // add a lot of code and the benefit wouldn't be that big. + union { + ErrorStackOverflow stack_overflow; + }; + ErrorDescription() { internal_memset(this, 0, sizeof(*this)); } + ErrorDescription(const ErrorStackOverflow &e) // NOLINT + : kind(kErrorKindStackOverflow), + stack_overflow(e) {} + + bool IsValid() { return kind != kErrorKindInvalid; } + void Print() { + switch (kind) { + case kErrorKindStackOverflow: + stack_overflow.Print(); + return; + case kErrorKindInvalid: + CHECK(0); + } + CHECK(0); + } +}; + +} // namespace __asan + +#endif // ASAN_ERRORS_H |